Which row's fields are returned when Grouping with MySQL?
I have a MySQL table with the fields id and name. ids are unique. names
are varchars and are non-unique.
I perform the following query:
SELECT id, name, COUNT( * ) AS frequency
FROM table
GROUP BY name
ORDER BY frequency DESC, id ASC
Questions
Assuming the first three rows all contain the same name.
Which id is going to be returned ( 1, 2, or 3 )?
Which id is this query going to ORDER BY ( Same as is returned? ... see
question 1 )?
Can you control which id is used? What if I wanted to return the largest
id, or the first id from a GROUP?
No comments:
Post a Comment