MySQL follows ANSI SQL. However, there are two differences the way GROUP BY works in MySQL and ANSI SQL.
  • In ANSI SQL you must group by all columns you specifies in the SELECT clause. MySQL does not have this restriction. You can have additional columns in the SELECT clause that are not in the GROUP BY clause.
  • MySQL also allows you to sort the group order in which the results are returned. The default order is ascending.
If you want to see the result of the query above in the descending order, you can do it as follows:
SELECT status, count(*)
FROM orders
GROUP BY status DESC;
Display:
As you see the status of orders now are in reverse alphabetical order. By default it is ascending order determined by ASC.

0 comments:

Post a Comment

 
Top
Blogger Template