UNION Queries

A UNION query can be used to combine the output of two queries into a 
single recordset.

That's pretty much what documentation says. But as always, it is important 
to read the small print:

"By default, no duplicate records are returned when you use a UNION 
operation".

That's right. To return ALL of the rows from two queries, always use the 
ALL predicate

SELECT x,y,z FROM t WHERE Condition1
UNION ALL
SELECT x,y,z FROM t WHERE Condition2

The query will run faster that way as well.

Sorry if you already knew that one, but I didn't, until it tripped me up.
Home About the Author Copyright © 2001 Adelle Hartley