Which query counts the number of employees NOT belonging to 'HR' Department from the relation 'EMP'?
Which query counts the number of employees NOT belonging to 'HR' Department from the relation 'EMP'?
Solution
The condition Dept != 'HR' keeps only the rows where the department is anything other than HR, and COUNT(*) counts those rows. So Option 4 counts the employees not in HR.
Options 1 and 3: both count employees who are in HR (= 'HR' and IN('HR') mean the same thing), which is the opposite of what is asked.
Option 2: NOT cannot be applied to COUNT(*) like this, so the query is invalid and does not filter any rows.
Rows where Dept is NULL are not counted by !=, because a comparison with NULL is never true.
Related questions:
2026: 13 May Shift 2
2026: 23 May Shift 1
2025: 16 May Shift 1
2026: 13 May Shift 2