0

Hey there, I need help with a query. The typical situation is like this:

I expect, say, 1000 rows out of a query that is based, say, on lastName column. One column is, say, firstName. I know I only have like twenty unique names that occur on multiple rows. I need to retrieve the five most frequent firstName-s in the 1000 row query result. can someone please guide me with this?

SELECT firstName FROM someTable WHERE lastName [meets some criteria] _______(what would allow me to retrieve the five most frequent firstName-s)

Any help greatly appreciated.

3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by bibiki
1

Something like this:

SELECT firstName, COUNT(*) AS nameCount 
FROM someTable
WHERE lastName = ''
GROUP BY firstName
ORDER BY nameCount DESC LIMIT 5
0

thank you both very much. I'm using pritaeas' code and certainly reading the info Lucaci andrew posted.

thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.