Skip to main contentSkip to solution

Which query counts the number of employees NOT belonging to 'HR' Department from the relation 'EMP'?

Solution

✅ Correct Option: 4

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question