PostgreSQL SyntaxLesson 36Free preview
PostgreSQL UNION
This lesson is part of PostgreSQL · All levels
Summary
UNION brings together the results of two or more SELECT queries into one combined row list. The main requirement is the same number of columns and the same data type as the interquery. Use UNION if you only want unique results, or UNION ALL if duplication is allowed and performance is preferred.
Key points
- Union combines the results of two queries with the same number of columns.
- Union deleted the duplicate, Union All maintained it.
- The column name follows the first query.
- Filtering is done individually through WHERE before merging.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.