The union operator in sql is used to combined two different queries into a singel table.
For eg:-we have one table which have information about employee, also have another table that have information about their department, and their is no relationship between them. Suppose that both employee and department table have one similar fields that have information about employee_id, and we want to get all information about employee_id from both the tables at the same time. We can do this by using union clause.
The important thing which have to be in mind while using union clause is that.
- All SELECT statement that we use to
combine in union query must have
same number of columns to be fetched
Syntax of union clause