Reputation: 3277
I am trying to take the different values between table2
to table1
(I should compare table2
to table1
).
I tried with Join
but unfortunately it doesn't work for me (or simply I don't know what to write).
table1:
id
---
1
2
table2:
id
---
4
5
7
2
3
1
Result should be - 4, 5, 7, 3
Upvotes: 1
Views: 124
Reputation: 115530
One more way:
SELECT id
FROM table2
WHERE id NOT IN
( SELECT id
FROM table1
)
Upvotes: 1
Reputation: 37388
SELECT t2.ID
FROM table2 t2
LEFT JOIN table1 t1 ON t1.ID = t2.ID
WHERE t1.ID IS NULL
Upvotes: 3
Reputation: 103358
SELECT id
FROM [TableB]
WHERE NOT EXISTS(SELECT id FROM [TableA] WHERE [TableA].id=[TableB].id)
Upvotes: 3