Wednesday, 21 April 2010

Describe UNION in mysql?

Union is used to merge records coming from different or same tables on different conditions.

for example:

SELECT id, name, age FROM employee WHERE id = 2
UNION
SELECT id, name, age FROM employee WHERE id = 5

Note:  both query contains same number of fields.


In above example, there are 3 fields in first query and 3 fields in second query.

Cheers!

No comments:

Post a Comment