Syntax :
Select table1.Column_Name1,table1.Column_Name2
from Table1
UNION
select table2.Column_Name1, table2.column_name2
from Table2
Consider the following table : Salary:
Emp_id | Emp_salary | Emp_name |
---|---|---|
01 | 25000 | Chandan |
02 | 30000 | Adhiraj |
03 | 25000 | Akshat |
Employee_record:
Emp_id | Emp_city | Emp_name |
---|---|---|
201 | noida | Sara |
202 | gurgaon | fatima |
Query of Union:
select Emp_id, Emp_name
from salary
UNION
select Emp_id, Emp_name
from designation
Emp_id | Emp_name |
---|---|
01 | Chandan |
02 | Adhiraj |
03 | Akshat |
201 | Sara |
202 | Fatima |
--------------------------------------------------------------------------------------------------------------- Sample Query for Intersection Here two select statement result will be combined but returns rows only from the first SELECT statement that are identical to a row in the second SELECT statement also first select statement result will appear and below it second select statement result will appear.
Syntax :
Select table1.Column_Name1,table1.Column_Name2
from Table1
Intersection
select table2.Column_Name1, table2.column_name2
from Table2
Consider the following table : Salary:
Emp_id | Emp_salary | Emp_name |
---|---|---|
01 | 25000 | Chandan |
02 | 30000 | Adhiraj |
03 | 25000 | Akshat |
Employee_record:
Emp_id | Emp_city | Emp_name |
---|---|---|
01 | noida | chandan |
04 | gurgaon | fatima |
Query of Union:
select Emp_id, Emp_name
from salary
INTERSECT
select Emp_id, Emp_name
from designation
Emp_id | Emp_name |
---|---|
01 | Chandan |
No comments:
Post a Comment