Answer the question
In order to leave comments, you need to log in
How does group by work?
Question. group by selects unique values. Ie, for example, if I need to select all unique urls, I will write ... group by url
Question. What is the default sort order? That is, records with which id will be included in the selection.
id url
1 /foo
2 /bar
3 /foo
4 /baz
in this case 1 or 3 will be in the selection?
Answer the question
In order to leave comments, you need to log in
GROUP BY has nothing to do with uniqueness - it's grouping.
If you specify only the second field in GROUP BY, and want to get id in SELECT, you will get an error.
All fields used in SELECT must be either grouped or aggregated (SUM, MIN, etc.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question