What is the difference between UNION
and UNION ALL
?
If there is no ORDER BY
, a UNION ALL
may bring rows back as it goes, whereas a UNION
would make you wait until the very end of the query before giving you the whole result set at once. This can make a difference in a time-out situation - a UNION ALL
keeps the connection alive, as it were.
So if you have a time-out issue, and there's no sorting, and duplicates aren't an issue, UNION ALL
may be rather helpful.