Reputation: 593
I have a scenario like this, there are 2 tables table_1 and table_2. Both table have a common column called column_1(no foreign_Key constraints!!). Table_1 can have some extra rows which are not present in table_2(In other words, table_2 is a sub-set of table_1). I want to list all those items which are only present in table_1 but not in table_2. Kindly help in writing the sql query for the same. Thanks in advance.
Upvotes: 2
Views: 100
Reputation: 370
select a.* from table1 a left outer join table2 b on a.col1=b.col1;
Upvotes: 0
Reputation: 1888
select * from table1
inner join table2 on table1.column1=table2.column1
Upvotes: 1
Reputation: 263943
SELECT a.*
FROM table1 a
LEFT JOIN table2 b
on a.column_1 = b.column_1
WHERE b.column_1 IS NULL
if those two tables are not related with each other, better add an index on table1.column_1
and table2.column_1
so that it won't require full table scan (which slows the performance)
Upvotes: 3