April 25, 2014 at 6:11 am
I want to find the rows in table A which are not present in table B.
Can this be done without comparing all colums ?
Ben
With the Count(*) function I can find the number of rows which are different, but not show the actual differences.
April 25, 2014 at 6:21 am
By definition, there is no "first row" in a table. It all depends on the columns in the ORDER BY section of the SELECT statement, what row will be presented as the "first row".
If you perform a LEFT OUTER JOIN to table B you'll get all rows from table A that do not match the criteria specified in the ON section of the query.
Using ORDER BY you can define, which row will be the "first row" to display.
April 25, 2014 at 6:30 am
Assuming A and B have the same schema:
select * from A
except
select * from B
April 25, 2014 at 6:31 am
Below are three different ways to identify what exists in TableA that does not exist in TableB. Pick your flavor.
--EXCEPT
SELECT * FROM TABLEA
EXCEPT
SELECT * FROM TABLEB
--LEFT OUTER JOIN
SELECT a.* FROM TABLEA AS a
LEFT OUTER JOIN TABLEB AS b
ON a.COL1 = b.COL1
WHERE b.COL1 IS NULL
--NOT EXISTS
SELECT * FROM TABLEA AS a
WHERE NOT EXISTS (SELECT 1 FROM TABLEB as B
WHERE a.COL1 = b.COL1)
April 25, 2014 at 6:36 am
gbritton1 (4/25/2014)
Assuming A and B have the same schema:
select * from A
except
select * from B
Thank you this is exactly what I was looking for.
Ben
LutzM (4/25/2014)
By definition, there is no "first row" in a table. It all depends on the columns in the ORDER BY section of the SELECT statement, what row will be presented as the "first row".Using ORDER BY you can define, which row will be the "first row" to display.
Although the above is completely true, I am missing the relevance off this in the scope of my question.
If you perform a LEFT OUTER JOIN to table B you'll get all rows from table A that do not match the criteria specified in the ON section of the query.
The question was : Can this be done without comparing all columns ?
I am familiar with the technique that I can find all rows in A with a left outer join, but I am looking for a technique were I do not have to compare all columns.
Thanks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply