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 2000 Forums
 Transact-SQL (2000)
 select distinct

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-11-26 : 08:32:57
kopi writes "sample table:

productNumber productName
1 prod1
2 prod1
3 prod3
4 prod3
5 prod5

I would like to select the rows where productName is unique

This is what I want to see
productNumber productName
1 prod1
3 prod3
5 prod5

What would be the select statement

Thanks
Kopi"

SamC
White Water Yakist

3467 Posts

Posted - 2002-11-26 : 08:39:25
Try:

SELECT DISTINCT productName, productNumber

Sam

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2002-11-26 : 08:41:52
SELECT MIN(ProductNumber), ProductName
FROM Products
GROUP BY ProductName

Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2002-11-26 : 10:07:56

I'm curious to know if you need the ProductNumber for a DISTINCT productName? If you do, do you need the Min, Max or Avg for a distinct productName?

Sam

Go to Top of Page
   

- Advertisement -