Last answered:

07 Nov 2021

Posted on:

27 Oct 2021

0

why removing where gives 12 rows and if we add where hire_date > "1999-01-01" we get 800+ results?

SELECT 
    COUNT(first_name), first_name, hire_date
FROM
    employees
WHERE
    hire_date > '1999-01-01'
GROUP BY first_name
HAVING COUNT(first_name) < 200; 

why is that when we remove the where code block we get 12 results and if we add that we get 800+ results?

1 answers ( 0 marked as helpful)
Instructor
Posted on:

07 Nov 2021

0

Hi data learner!

Thanks for reaching out.

This is a great question indeed! It regards the particular way in which we use the WHERE clause in a SELECT statement.
Basically, the condition we set in a WHERE clause will be applied to all records from the designated data tables. I.e., this will be done prior to applying any aggregate functions (such as COUNT()).
That's why, the output changes - the WHERE block sets a condition that in this case, affects the number of rows returned.

Hope this helps.
Best,
Martin

Submit an answer