SQL Puzzler - Join T and DISTINCT(T)
Date: 2 Mar 92 18:47:35 GMT
Message-ID: <matthew.699562055_at_pram.cs.ucla.edu>
OK, all you SQL "wizards". I used to hope to count myself amongst your
number, until I stumbled onto this little problem. This is *not* a
homework problem (although it'd make a darned good one).
First, I'm using Oracle, but this is a general SQL problem.
I have a table, let's call it 'T', with two attributes (A & B), having the
following values:
A B
1 x
1 x
1 x
1 y
1 y
[ rest of table has other values for A - deleted as not germaine ]
B B
x y x y y x y x y x
To recap:
Let R = SELECT DISTINCT * from T
Now, I want:
SELECT R.B T.B
WHERE R.A = T.A AND R.B != T.B
However, I'd like to do these two steps in a *single* (presumably nested) SQL
statement. It sounds easy, but it's turning into a nightmare.
I can (and have) done it using ORACLE PL/SQL, by the way.
Questions:
- Is there a general single SQL statement that will join a table with
it's distinct version?
- Is there an ORACLE SQL*PLUS query to do the same thing (note that ORACLE != SQL)?
-- Matthew Merzbacher ARPA: matthew_at_CS.UCLA.EDU Moo - Moo Moo UUCP: ...!{uunet|rutgers|ucbvax}!cs.ucla.edu!matthew This time, *with* the oysReceived on Mon Mar 02 1992 - 19:47:35 CET