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
 SQL Server Development (2000)
 Distinct

Author  Topic 

lane0618
Posting Yak Master

134 Posts

Posted - 2002-05-22 : 10:52:12
I have a view in which I am trying to select a distinct list. When I try to use the distinct command on the following table, I end up with all 5 rows because there are different description for the same item.

ITEM Description
a desc1
a desc2
a desc3
b desc4
b desc5

I don't care about losing description 2,3 and 5. I want my view to return this:

ITEM Description
a desc1
b desc4

How is this possible?

Thanks,
Lane


YellowBug
Aged Yak Warrior

616 Posts

Posted - 2002-05-22 : 11:00:15
You can try something like this:

select ITEM, max(DESCRIPTION)
FROM myTable
GROUP BY ITEM
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-05-22 : 11:00:25

select item, min(description
from <tablename>
group by item


<O>
Go to Top of Page

lane0618
Posting Yak Master

134 Posts

Posted - 2002-05-22 : 12:43:28
Perfect!

Thanks!
Lane

Go to Top of Page
   

- Advertisement -