First page Back Continue Last page Image

The Union Keyword

Like a Join a UNION merges data in the query result, But this is more like a Cut and Paste Operation with rules for getting a reasonable result

In General the 2 data results (Usually a table but could be a query result) being merged must have a complementary sequence of fields (Best if they are identical)

SELECT *

FROM planets

LEFT JOIN moons USING (Diameter_km)

UNION ALL

SELECT *

FROM planets

RIGHT JOIN moons USING (Diameter_Km)

ORDER BY Diameter_km;

We actually already did one in a previous example

These 2 queries being joined produce the exact same field layout

The union just pasted the 2nd result to the bottom of the first