Set Operations (SQL)

Set Operations (SQL)

In SQL the UNION clause combines the results of two SQL queries into a single table of all matching rows. The two queries must result in the same number of columns and compatible data types in order to unite. Any duplicate records are automatically removed unless UNION ALL is used.

UNION can be useful in data warehouse applications where tables aren't perfectly normalized. A simple example would be a database having tables sales2005 and sales2006 that have identical structures but are separated because of performance considerations. A UNION query could combine results from both tables.

Note that UNION does not guarantee the order of rows. Rows from the second operand may appear before, after, or mixed with rows from the first operand. In situations where a specific order is desired, ORDER BY must be used.

Note that UNION ALL may be much faster than plain UNION.

Read more about Set Operations (SQL):  INTERSECT Operator, EXCEPT Operator

Famous quotes containing the words set and/or operations:

    Unfortunately, many things have been omitted which should have been recorded in our journal; for though we made it a rule to set down all our experiences therein, yet such a resolution is very hard to keep, for the important experience rarely allows us to remember such obligations, and so indifferent things get recorded, while that is frequently neglected. It is not easy to write in a journal what interests us at any time, because to write it is not what interests us.
    Henry David Thoreau (1817–1862)

    Plot, rules, nor even poetry, are not half so great beauties in tragedy or comedy as a just imitation of nature, of character, of the passions and their operations in diversified situations.
    Horace Walpole (1717–1797)