Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Use of max function

Author  Topic 

iampok
Starting Member

1 Post

Posted - 2009-08-11 : 00:51:22
I am learning SQL, and have a sample DB which is made up of customer orders for different products.
One query I ran shows the most sold product:
SELECT prodID, description, SUM(quantity)
FROM orderItem NATURAL JOIN product
GROUP BY prodID, description
ORDER BY SUM(quantity) DESC
LIMIT 1;


However what happens if two products are the best selling how do I display them both? (like having the query check it, not just user setting "LIMIT 2")

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-08-11 : 01:11:36
Dear this forum is dedicated to Sql Server, and your query is related to oracle... find out the correct forum, for better answer

However LIMITclause basically is like Top clause in Sql Server which restrict the number of output rows.
Go to Top of Page
   

- Advertisement -