Today, I will discuss about the scenario/Problem which i faced in current project.
Problem Statement : You have two Employee tables having data mentioned below.
| Emp-1 | |
| EmpId | EmpName |
| 1 | Shivani |
| 2 | Gaurav |
| 3 | Radhe |
| 4 | Rahul |
| 5 | Anil |
| Emp-2 | |
| EmpId | EmpName |
| 1 | Shivani |
| 6 | Ashok |
| 3 | Radhe |
| 7 | Vikram |
| 4 | Rahul |
Output :
| EmpId | EmpName |
| 2 | Gaurav |
| 5 | Anil |
| 6 | Ashok |
| 7 | Vikram |
Solution : Here, you need to use except or minus based on the database you are using and union clause. See the below query for the same.
select EmpId ,EmpName from Emp-1
except
select EmpId ,EmpName from Emp-2
union
select EmpId ,EmpName from Emp-2
except
select EmpId ,EmpName from Emp-1
