SQL Union
- User
SQL Union
- Assistant
The SQL
UNIONoperator is used to combine the result sets of two or moreSELECTqueries into a single result set. By default, it removes duplicate rows between the variousSELECTstatements. If you want to include duplicates, you can useUNION ALL.Here are some key points about using
UNION:-
Number of Columns: Each
SELECTquery must have the same number of columns in the result sets with similar data types. -
Column Order: The columns selected by each query must appear in the same order.
-
Column Names: The column names in the final result set are usually taken from the first
SELECTstatement.
Here is a basic example of using
UNION:sqlSELECT column1, column2 FROM table1 UNION SELECT column1, column2 FROM table2; -