Multiple choice technology databases

The following query fails. Select employee_name,employee_id,count() from employee_Details group by employee_id where count()>2; The right format is:

  1. Select employee_name,count() from employee_Details group by employee_id where count()>2;

  2. Select employee_name,employee_id,count() from employee_Details group by employee_id having count()>2;

  3. Select employee_name,employee_id,count() from employee_Details order by employee_id where count()>2;

  4. NONE of THE ABOVE

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The SQL query fails because aggregate functions like count(*) cannot be evaluated in a WHERE clause. To filter groups created by GROUP BY, the HAVING clause must be used. Note that the query also selects employee_name which is not in the GROUP BY clause, but the syntax error of WHERE count(*) is resolved by changing it to HAVING count(*) in standard SQL execution rules.