Discussion Locked

SQL Query

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How can i build the sql query for checking the rows in one table A, which is not exist in table B and vice versa. in a single query?

7 replies

by oliviu

Having 2 tables A and B, to get the rows from table A which don't exist in table B and those from table B which don't exist in table A run this:

(select * from A minus select * from B)
union
(select * from B minus select * from A);

Good Lock

by glen_mcleod

Try this one, it's a little more straightforward.

Select *
From A Left Join B on B.CommonColumn = A.CommonColumn
Where B.CommonColumn Is Null

"CommonColumn" refers to the name of the column that is common to both tables.

Glen

by melanie_norton

SELECT column name FROM table A
WHERE NOT EXISTS
(SELECT column name FROM table B
WHERE A.column name = B.column name)

or

SELECT DISTINCT column name
FROM table A
WHERE column name NOT IN
(SELECT column name
FROM table B)

This discussion is closed to new replies.