Re: Selct DISTINCT

From: Arch <send.no_at_spam.net>
Date: Tue, 29 Jan 2008 15:51:05 -0500
Message-ID: <vc4vp39dfsi42kb5k0r4g5uvj8mrcun80o@4ax.com>


On Tue, 29 Jan 2008 12:29:28 -0800 (PST), trpost_at_gmail.com wrote:

>Let me expand a little on what I am actually doing, I provided a small
>example in the original post as I thought there might be a simple way
>to select the first distinct row based on one column.
>
>Without specifics, here is how my query is structured:
>
>
>SELECT DISTINCT(ID), NAME, SSN FROM
>(
>
> SELECT DISTINCT(ID), NAME, SSN FROM TABLE1
>
> UNION ALL
>
> SELECT DISTINCT(ID), NAME, SSN FROM TABLE2
>
>)
>
>So the problem I have is that there is some duplicate data in TABLE1
>and TABLE2, but TABLE1 data always has more data available then in
>TABLE2, so that is how I know if there is a duplicate to take the
>first row.

Use UNION instead of UNION ALL, duplicates will be discarded. Received on Tue Jan 29 2008 - 14:51:05 CST

Original text of this message