Unions

The UNION operation lets you combine the results of two or more different SQL statements into one answer set. You can combine many different tables or SQL statements using the UNION operator; the only restriction is that every table or SQL statement must have the same type, number, and order of columns.

Suppose you wanted to combine the minimum and maximum scores for each of the DB2 Certification program exams and add a string constant that indicates which values are the maximum and minimum.

SELECT NUMBER,'MINIMUM:', MIN(INTEGER(SCORE))
FROM TEST_TAKEN
GROUP BY NUMBER
UNION
SELECT NUMBER,'MAXIMUM:', MAX(INTEGER(SCORE))
FROM TEST_TAKEN
GROUP BY NUMBER
ORDER BY NUMBER,2

The UNION operator shows you the results of two or more separate queries ...

Get DB2® Universal Database for OS/390® Version 7.1 Certification Guide 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.