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
 MOST POPULAR PRODUCT

Author  Topic 

frank88
Starting Member

4 Posts

Posted - 2008-12-03 : 08:42:19
Hey,

I have got three tables Order_Line (shows the different orders that have been made), product (shows the different products and details) and wishlist (shows which products are wanted by customers).

I want to write a query that will show me what the most popular product is that appears in the orders table and the wish list table.

Or alternatively a count that will show how many of each product have been bought and are wanted.

Can anyone help.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-12-03 : 08:55:33
do this for both tables:
select top 1 productId, count(*) as cnt
from yourTable
group by productId
order by count(*) desc

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

frank88
Starting Member

4 Posts

Posted - 2008-12-03 : 09:04:16
Thanks for the help
Go to Top of Page
   

- Advertisement -