Last answered:

05 May 2020

Posted on:

01 May 2020

0

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)
Instructor
Posted on:

05 May 2020

0
Hi Alan! Thanks for reaching out. If I've managed to understand you correctly, you are referring to the following query, right?
SELECT 
first_name, COUNT(first_name)
FROM
employees
GROUP BY first_name;
If yes, then the output is not sorted in alphabetical order only because you have not added an ORDER BY clause in the following way.
SELECT 
first_name, COUNT(first_name)
FROM
employees
GROUP BY first_name
ORDER BY first_name;
Hope this helps.
Best,
Martin

Submit an answer