Group By with count
On the Group by lesson, we have the query
Select first_name
from employees
group by first_name;
I match results, but when I add in COUNT after SELECT and before (first_name)
my returned results come back different with the same order of names or counts before the count function was added.
In other words, when adding the first_name before count(First_name) it comes back alphabetical, while mine comes out in order of Georgi, Bezalel, Parto etc.
Is this normal or okay, as long as the point of the query gets across, or must the results match exactly?
1 answers ( 0 marked as helpful)
Hi Alan!
Thanks for reaching out.
If I've managed to understand you correctly, you are referring to the following query, right?
Best,
Martin
SELECTIf yes, then the output is not sorted in alphabetical order only because you have not added an ORDER BY clause in the following way.
first_name, COUNT(first_name)
FROM
employees
GROUP BY first_name;
SELECTHope this helps.
first_name, COUNT(first_name)
FROM
employees
GROUP BY first_name
ORDER BY first_name;
Best,
Martin