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)
 Select distinct column value

Author  Topic 

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-01-08 : 01:44:04
Hi,
I have a table test having the following values

no desc
1 name1
1 test
1 data
2 xyz
3 temp
3 regular

Now I want to display the same in the following way

no desc
1 name1
test
data
2 xyz
3 temp
regular

I used the query

select (Select no from test where no=t.no group by no having count(no) =1), desc from test t order by no

but it produced the result

no desc
null name1
null test
null data
2 xyz
null temp
null regular

Is there any solution?

Madhivanan

Kristen
Test

22859 Posts

Posted - 2005-01-08 : 06:42:15
[code]
SELECT CASE WHEN EXISTS (SELECT * FROM test T2 WHERE T2.no = T1.no AND T2.desc > T1.desc)
THEN NULL
ELSE no
END,
desc
FROM test T1
ORDER BY no, desc
[/code]
Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-01-08 : 07:27:10
Thanks Kristan. It works well

Madhivanan
Go to Top of Page
   

- Advertisement -