tags:

views:

149

answers:

1

I have a sql statement that is a union of several queries which all just return keys:

SELECT DISTINCT key as KEY FROM tablea WHERE XYZ
    UNION ALL
SELECT DISTINCT id as KEY FROM tableb WHERE XYZ
    UNION ALL
...

My question is that there are some queries that return keys that overlap, and I actually want the final KEY field returned values to be distinct values. Any ideas?

+2  A: 

Use UNION instead of UNION ALL.

Eugene
Or, if you're a mazochist :) then you can surround your query like this:SELECT DISTINCT KEY FROM (YOURQUERYHERE) AS aWorks on SQL Server. But UNION should work.
Eugene
Ha... I like it. Not the mazochist I once was though.
Brian
Thanks a lot Eugene! Worked great!
Brian