Junior
What is the purpose of the UNION keyword in SQL?
sobes.tech AI
Answer from AI
The keyword UNION is used to combine the results of two or more SELECT statements into a single result set. In this case:
- Each
SELECTstatement must return the same number of columns. - Corresponding columns in each
SELECTstatement should have similar data types.
By default, UNION removes all duplicate rows from the combined set. If you want to include all rows, including duplicates, use UNION ALL.
Example of using UNION:
SELECT column1, column2 FROM Table1
UNION
SELECT column1, column2 FROM Table2;