SQL · Question 13 · Hard

SQL question 13

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

What does this query return?

SELECT COUNT(*)
FROM Employee e1
JOIN Employee e2
  ON e1.salary = e2.salary AND e1.id < e2.id;
  1. 2
  2. 6
  3. 0
  4. 1
Answer and explanation

Answer: D. 1

Explanation: Only Ravi (id 2) and Vikram (id 6) share a salary (50000). The condition e1.id < e2.id keeps just the pair (2, 6), so the count is 1. NULL = NULL is not TRUE, so Karan never matches.

Previous: Table Employee: id | name | dept | salary 1 | Asha | HR | 30000 2 | Ravi | IT… · Next: Table A has one column x with rows: 1, 1, 2, NULL Table B has one column x…

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