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 leave distinct values for UNION?

Author  Topic 

hornet
Yak Posting Veteran

96 Posts

Posted - 2006-11-02 : 04:50:31
Hi all!
I have to retrieve distinct values for the query which is using UNION.
e.g.
SELECT DISTINCT(peny) FROM
(SELECT DISTINCT(peny) FROM A
UNION ALL SELECT DISTINCT(peny) FROM B
UNION ALL SELECT DISTINCT(peny) FROM C)

How can i do it?
thanks in advance!

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2006-11-02 : 04:53:20
Using UNION without the ALL returns distinct values already

select peny from a union
select peny from b union
select peny from c


Duane.
Go to Top of Page
   

- Advertisement -