Frequently Asked Questions
What is the difference between UNION and UNION ALL?
What is the difference between UNION and UNION ALL?
UNION combines results and removes duplicates. UNION ALL keeps all rows including duplicates, which is typically faster since no deduplication is needed.
Do column names need to match in UNION queries?
Do column names need to match in UNION queries?
Yes. The number and names of columns must be identical across all queries combined with UNION. Use
AS aliases to ensure column names match.Can I use ORDER BY with UNION?
Can I use ORDER BY with UNION?
ORDER BY can be applied to the final combined result set after the UNION. Each individual query in the union cannot have its own ORDER BY unless wrapped in a CALL {} subquery.