Tuesday, 21 February 2012

Q; What is union and intersection in mysql?


Like SQL standard, MySQL UNION allows you to combine two or more result sets from multiple tables together. The syntax of using MySQL UNION is as follows:
SELECT statement UNION [DISTINCT | ALL] SELECT statement UNION [DISTINCT | ALL]
Suppose you want to combine customers and employees infomation into one result set, you use the following query:
SELECT customerNumber id, contactLastname name
FROM customers
UNION
SELECT employeeNumber id,firstname name
FROM employees

No comments:

Post a Comment