UNION

Syntax:

SELECT...
  UNION [ALL]
  SELECT
    [UNION
    SELECT ...]

Description: Combines the resultsets of several SELECT queries into a single resultset.

Without ALL specified, the rows of the final resultset will be unique (like a SELECT DISTINCT). With ALL, the rows from all the SELECT statements will be included.

Limitations: Version 4.0.0 and later. Only the last SELECT can have INTO OUTFILE or ORDER BY.

Description in: Day 8

See also: SELECT

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.