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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Group items that have > 0 by media?

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2012-01-12 : 13:26:03
Hello I'm trying to make a list of everything we have stock on and I want it to just show 1 thing the media type of what we have stock on. So far I did this:

SELECT Media
FROM Products
WHERE (StockQty > 0)
ORDER BY Media

That returns over 40,000 results with multiple listings of the same thing. How can I tell sql to just show me the media once?

Thanks

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-12 : 13:33:21
SELECT DISTINCT Media
FROM Products
WHERE (StockQty > 0)
ORDER BY Media

SELECT Media, SUM(StockQty)
FROM Products
GROUP BY Media
HAVING SUM(StockQty) > 0

Not sure what you really want. Need sample Data, what you are seeing, and what the expected results should be




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2012-01-12 : 14:56:17
SELECT DISTINCT Media
FROM Products
WHERE (StockQty > 0)
ORDER BY Media

Worked perfectly. THanks
Go to Top of Page
   

- Advertisement -