Reputation: 2101
Does it matter which comes after which? I mean if I do
SELECT * FROM table GROUP BY x ORDER BY y
will the results first be grouped and then ordered?
Upvotes: 2
Views: 256
Reputation: 5588
WHERE
conditionGROUP BY
ORDER BY
Example :
SELECT * FROM table GROUP BY columnanme ORDER BY columnanmae
Upvotes: 1
Reputation: 263703
ORDER
is the last clause to be executed.
The order of execution
For more info, please click here
Upvotes: 8
Reputation: 2867
In MySQL, a GROUP BY
clause has the side effect of sorting columns as well. If you already have a GROUP BY
clause in your query that produces the desired sort order, there's no need for an ORDER BY
.
Upvotes: 0