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)
 How to retriev non duplicate data from a column

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-01-19 : 08:10:53
John writes "Hi, I have this table

Table Name:Test
Column name | datatype | size | value
---------------------------
Col1 varchar 10 Banana
Col2 varchar 10 Banana
Col3 varchar 10 Apple
Col4 varchar 10 Apple

and I want this result

Banana
Apple

e.g. getting the non duplicate value from the column.
I know there is a built in function that doing that using
the Select statement? can you help please"

RM
Yak Posting Veteran

65 Posts

Posted - 2005-01-19 : 08:52:11
What is the query that you are using ?
From the example you've given, you will have to query the table like this ... Select Col1 From Test UNION Select Col2 From Test UNION Select Col3 From Test UNION Select Col4 From Test

to get your desired output

and if you have this table structure

Table Name:Test
Column name | datatype | size | value
---------------------------
Col1 varchar 10 Banana
Banana
Apple
Apple

then use SELECT DISTINCT col1 FROM Test
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-01-19 : 12:50:55
[code]WHILE EXISTS( SELECT fruit FROM tab
GROUP BY fruit HAVING COUNT(*) > 1 )
BEGIN
EAT fruit;
END

SELECT fruit FROM tab[/code]

But if that gives you a stomachache, you can check out the distinct keyword.

rockmoose
Go to Top of Page
   

- Advertisement -