about 9 years ago
UNION CLAUSE
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
eg;-
Below is a selection from the "Customers" table:
- CustomerID CustomerName Address City PostalCode
- 1 suresh tilak road rishikesh 240098
- 2 amit survey road bahadurgarh 293400
- 3 saurav neshvilla road dehardun 248001
CustomerID CustomerName Address City PostalCode 1 suresh tilak road rishikesh 240098 2 amit survey road bahadurgarh 293400 3 saurav neshvilla road dehardun 248001
And a selection from the "Suppliers" table:
The following SQL statement give all the different cities from the "Customers" and the "Suppliers" tables:-
OUTPUT
0 Comment(s)