I have table A:
ID int
Name text
And Table B
ID int
Name text
Now, I want to select all records from A where there is no matching record in B based on the ID
I want to do this with a JOIN statement and not a subquery as I understood that the execution plan for JOIN statements is more efficient...
Any help?
Something like this:
select *
from TableA
left outer join TableB
on TableA.ID= TableB.ID
where TableB.ID is null
The inner query does an outer join, all records show up, some with nulls
The outer query gets the records with null
|||SELECT A.* FROM A LEFT OUTER JOIN B on A.ID = B.ID WHERE B.ID IS NULL
I would strongly advise comparing performance with
SELECT * FROM A WHERE A.ID NOT IN (SELECT ID FROM B)
sql
No comments:
Post a Comment