[prog] newbie SQL query assistance needed

Chris Wilson chris+linuxchix at aptivate.org
Tue Apr 27 20:16:30 UTC 2010


Hi Tina,

On Tue, 27 Apr 2010, Tina wrote:

> I have an orders table. In it are all the orders (orderid) with each item
> ordered (itemid) and quantity (quantity).
> 
> I need to figure out which item was ordered the most times. I know it
> involves a multi-row query, but I just can't seem to figure it out.

select itemid, count(1) from orders group by itemid;

You might like to study the "group by" clause of the SQL SELECT statement, 
it's extremely useful.

Cheers, Chris.
-- 
Aptivate | http://www.aptivate.org | Phone: +44 1223 760887
The Humanitarian Centre, Fenner's, Gresham Road, Cambridge CB1 2ES

Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.


More information about the Programming mailing list