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
 wishlist

Author  Topic 

sambrown180
Starting Member

38 Posts

Posted - 2008-12-09 : 11:33:51
i want to make a wishlist query with the most popular product at the top of the results. The information shall be taken from one table

in it will be product id and product price

please can you tell me what coding do i need to write

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 11:35:25
most popular on what basis? based on price?
Go to Top of Page

sambrown180
Starting Member

38 Posts

Posted - 2008-12-09 : 11:38:44
O on how many people added it to their wshlist. so i take it List_ID is also required
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 11:41:39
[code]SELECT productid
FROM YourTable
GROUP BY productid
ORDER BY COUNT(List_ID) DESC[/code]
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-12-09 : 11:43:06
If visakh's query doesn't work, post the schema of the tables involved. Without that, all we can do is guess.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

sambrown180
Starting Member

38 Posts

Posted - 2008-12-09 : 12:09:11
In my wishlist I have

List_ID as my primary key
Customer_ID as a foreign key
Product_ID as a foreign key
Product_Price

I tried that query above and it doesnt work any suggestions on any other codes?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 12:12:32
post sufficient detail as per below link and then we will think of helping you further

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

sambrown180
Starting Member

38 Posts

Posted - 2008-12-09 : 12:19:19
I done this code

SELECT Product_ID
FROM Wishlist
GROUP BY Product_ID
ORDER BY COUNT(List_ID) DESC

but it doesnt seem to be working and it doesnt include product price. Where would I put product price
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-09 : 12:22:47
SELECT Product_ID ,Product_Price
FROM Wishlist
GROUP BY Product_ID,Product_Price
ORDER BY COUNT(List_ID) DESC

slight modification to vishak's solution....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 12:24:52
quote:
Originally posted by sambrown180

I done this code

SELECT Product_ID
FROM Wishlist
GROUP BY Product_ID
ORDER BY COUNT(List_ID) DESC

but it doesnt seem to be working and it doesnt include product price. Where would I put product price


did you see link i posted. whats is stopping you from posting information asked? cant you understand we cannot see your system nor can we read your mind? how will we know what all you want as output?


SELECT w.*
FROM wishlist w
INNER JOIN (
SELECT Product_ID,COUNT(List_ID) AS Subscription
FROM Wishlist
GROUP BY Product_ID
)t
ON t.Product_ID=w.Product_ID
ORDER BY t.Subscription DESC
Go to Top of Page

sambrown180
Starting Member

38 Posts

Posted - 2008-12-09 : 12:46:58
thanks for all the help i have sorted it now
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-09 : 12:48:56
cheers
At least in future provide relevant info for helping us to help you fast.
Go to Top of Page
   

- Advertisement -