SQL · Question 6 · Medium

SQL question 6

Table Employee:
id | name | dept | salary
1 | Asha | HR | 30000
2 | Ravi | IT | 50000
3 | Neha | IT | 60000
4 | Karan | Sales | NULL
5 | Priya | HR | 45000
6 | Vikram | IT | 50000

How many rows does this query return?

SELECT dept, COUNT(*)
FROM Employee
GROUP BY dept
HAVING COUNT(*) >= 2;
  1. 1
  2. 2
  3. 3
  4. 6
Answer and explanation

Answer: B. 2

Explanation: The groups are HR (2 rows), IT (3 rows) and Sales (1 row). HAVING COUNT(*) >= 2 keeps HR and IT, so 2 rows are returned.

Previous: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT… · Next: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT…

Practise sql

Try a fresh set of sql questions with an explanation after every answer, free and without signing up: SQL practice. Or sit a full placement mock test.

More sql questions

More technical & programming practice

Operating Systems · Computer Networks · Software Engineering · Cloud & DevOps · GenAI Basics · Pseudo-code · C Programming · Java

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge