Re: Basic SQL
- From: "John Gilson" <jag@xxxxxxx>
- Date: Wed, 13 Jul 2005 21:25:08 GMT
"MS" <mesemailoffers@xxxxxxxxxxx> wrote in message
news:1121280375.735695.277470@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I am trying to write a sql statement that gives me the records that
> have multiple values for column b, but cannot figure it out - can
> someone help?
>
> My table is as follows:
>
> ID Value
> 1234 S
> 1234 S
> 1234 X
> 4444 S
> 5555 X
> 5555 Y
>
> I want to see what records have two distinct values for the "Value"
> column. The results of the query when running against the above data
> should be as follows:
>
> ID Value
> 1234 S
> 1234 X
> 5555 Y
> 5555 X
>
> Any help would be appreciated.
>
> Thanks!
SELECT ID, Value
FROM (SELECT DISTINCT id, value FROM T) AS T
WHERE EXISTS (SELECT * FROM T AS T1
WHERE T1.ID = T.ID AND
T1.Value <> T.Value)
--
JAG
.
- Follow-Ups:
- Re: Basic SQL
- From: Stefan Rybacki
- Re: Basic SQL
- References:
- Basic SQL
- From: MS
- Basic SQL
- Prev by Date: Re: Basic SQL
- Next by Date: Re: Basic SQL
- Previous by thread: Re: Basic SQL
- Next by thread: Re: Basic SQL
- Index(es):
Relevant Pages
|