faqts : Computers : Databases : MySQL : Language and Syntax

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

31 of 36 people (86%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I use "group by" and "order by" togehter?

Oct 4th, 2000 14:05
Narendra Jain, Robert M. Muench,


'order by' always comes after the 'group by' clause of the select
statement. The general format is:
select customer, count(*) as inv_cnt
from invoices
group by customer
order by inv_cnt desc;
The above query groups the invoices table by customer and arranges them
in the order of the customer with the maximum invoice.