SQL TutorialLesson 32Free preview
SQL Union
This lesson is part of SQL · All levels
Summary
UNION combines the results of two or more SELECT queries into one set of rows vertically. The requirement is that each query should have the same number of columns and a compatible data type. UNION automatically removes the duplicate line from the combined result.
Key points
- UNION brings the query results together vertically, not horizontally.
- The number of columns on both queries should be the same.
- The corresponding data type of the column must be compatible.
- UNION removes duplicates; use UNION ALL when duplicates are to be maintained.
- The ORDER BY at the end applies to all combined results.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.