If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Inner Join Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-04, 21:09
vivek_vdc vivek_vdc is offline
Registered User
 
Join Date: Sep 2003
Posts: 176
Inner Join Question

To find non-matching rows between two tables A & B whose PK is a composite key of three cols, I use the query -

SELECT DISTINCT A.*
FROM Table1 A
INNER JOIN Table2 B
ON A.[Col1] <> B.[Col1]
AND A.[Col2] <> B.[Col2]
AND A.[col3] <> B.[col3]

I need the non-matching rows of Table A only. My question is - Is the above query correct? Any better way to find non-matching rows of A.

Thanks
Reply With Quote
  #2 (permalink)  
Old 06-27-04, 22:30
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
Your query will not work.

1)
Select *
from tableA ta
where NOT EXISTS
(select null
from tableB tb
where ta.a = tb.a AND
ta.b = tb.b AND
ta.c = tb.c)

2)
Select *
from tableA ta
LEFT OUTER JOIN
tableB tb ON
ta.a = tb.a AND
ta.b = tb.b AND
ta.c = tb.c
WHERE tb.a IS NULL
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #3 (permalink)  
Old 06-27-04, 23:19
vivek_vdc vivek_vdc is offline
Registered User
 
Join Date: Sep 2003
Posts: 176
Thanks. I shall use option 2.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On