SOF User
SOF User

Reputation: 7840

sql query help between two tables

Table 1

table1
row 1 
row 2
row 3

Table 2

table2
row 1

Want query which show only rows of table1 which is not in table2

Result

result
row 2
row 3

Upvotes: 0

Views: 54

Answers (2)

Richard Schneider
Richard Schneider

Reputation: 35464

select table1.col1 from table1
where not exists 
   (select table2.col1 from table2 where table1.col1 = table2.col1)

Upvotes: 1

mu is too short
mu is too short

Reputation: 434985

SQL set operators are your friend:

SELECT row FROM table1
EXCEPT
SELECT row FROM table2

Or you can use NOT IN:

SELECT row
FROM table1
WHERE row NOT IN (SELECT row FROM table)

These assume that your tables have one column called row and that the columns are the same type. You should be able to adapt them to your real tables easily enough though.

Upvotes: 2

Related Questions