December 5, 2007 at 10:28 pm
I have a proc and I'm selecting data into
Temp table A (col1,col2,col3,col4) that meets certain conditions.
Then, I'm selecting data into
Temp table B (col1,col2,col3,col4) that meets certain conditions.
What I would like to do is then select * from Temp table A that's not in Temp table B. Then I want to select everything from Temp table B that's not in Temp table A.
I'm just not sure of the where clause.
Example:
Temp table A
col1...col2...col3...col4
joe....table..saw...yellow
bob....table..saw...green
phil....table..saw...yellow
Temp table B
col1...col2...col3...col4
joe....table..saw...yellow
dan....table..saw...yellow
First result set from select
bob....table..saw...green
phil....table..saw...yellow
Second result set from select
dan....table..saw...yellow
December 5, 2007 at 11:07 pm
SELECT * FROM TempTableA A
WHERE NOT EXISTS
(SELECT * FROM TempTableB Z WHERE Z.col1 = A.col1 AND Z.col2 = A.col2 AND Z.col3 = A.col3 AND Z.col4 = A.col4)
December 5, 2007 at 11:14 pm
Hi,
you can try out the following queries:
select * from A where A.col1 not in
(select A.Col1, from Table A, Table B where A.col1=B.col1)-- This will fetch common results in both the tables
select * from B where B.col1 not in
(select A.Col1, from Table A, Table B where A.col1=B.col1)
Hope that helps..:)
Regards,
Avaneesh Bajoria.
December 5, 2007 at 11:32 pm
How about all having in a single query...
SELECTA.*, B.*
FROMTempTableA A
FULL OUTER JOIN TempTableB B ON A.col1 = B.col1 AND A.col2 = B.col2 AND A.col3 = B.col3 AND A.col4 = B.col4
--Ramesh
December 6, 2007 at 12:03 am
Ya beat me to it, Ramesh!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply