I want to fetch the unmatching records from two table in SQL, the table structure is as follows:
Table1
Id      Name
1       Prashant
2       Ravi
3       Gaurav
5       Naween
7       Sachin
Table2
Id      Name
1       Prashant
2       Ravi
4       Alok
6       Raja
The output I want is
Id      Name
3       Gaurav
4       Alok
5       Naween
6       Raja
7       Sachin
What will be the query to fetch the required output in SQL?
I think joeslice's answer will only give half the results. You need to union the other table. Alternatively, you could do a full outer join.
select a.Id, a.Name from Table1 a left outer join Table2 b on a.Name = b.Name where b.Id is null
UNION ALL
select a.Id, a.Name from Table2 a left outer join Table1 b on a.Name = b.Name where b.Id is null
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With