Retrieve diff columns while not included wthin Group by
I see some student write this code on the Q&A section : I'm wondering how this code will work without using the column hire_date as well within "Group By", how you can group data based on one column while the results we want to retrieve include another column that probably contains diff values for each row "first_name" (I don't think all group of 'first_name' have the same hire_date)
COUNT(first_name), first_name, hire_date
hire_date > '1999-01-01'
GROUP BY first_name
HAVING COUNT(first_name) < 200;
Thanks for reaching out.
Actually, it is not compulsory to use the hire_date column in the GROUP BY clause. You use this column which you would like to group the result set by.
Hope this helps.
No, I mean we can't retrieve in the same time a column with multiple records hire_date and a column that return only a single value COUNT(first_name) without grouping the records by this column (hire_date)
Actually, I see the answer to my question farther in the course, here:
We can't retrieve by SELECT an aggregate function and another column without grouping by this column in other versions of SQL.