Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate two tables

I have two tables and I want to get all records from one table that are different from the records in second table.

Eg.: if we have four records in the first table like A,B,C,D and three records in the second table thats A,B,C then the answer of query should be D.

I have tried "EXCEPT" operator but it doesn't work fine. Kindly help me in writing correct query for the given problem.

like image 752
Nemat Avatar asked Dec 09 '22 16:12

Nemat


1 Answers

How about:

select * from TABLE_A where (COL,COL2,..) not in (select COL1,COL2,.. from TABLE_B) 
union all 
select * from TABLE_B where (COL1,COL2,..) not in (select COL1,COL2,.. from TABLE_A); 
like image 84
modz0r Avatar answered Dec 25 '22 21:12

modz0r