In MySQL, the "UNION" operator is used to combine the result sets of two or more "SELECT" statements into a single result set.
The UNION operator eliminates duplicate rows from the combined result set.
It's important to note that the "UNION" operator requires that the number of columns in the "SELECT" statements must be the same, and the corresponding columns must have compatible data types.
SELECT column1, column2, ... FROM table1 WHERE condition UNION SELECT column1, column2, ... FROM table2 WHERE condition;
column1, column2, ...: The columns we want to select from the tables.
table1, table2, ...: The tables from which we are selecting data.
WHERE condition: Optional, specifies a condition for each SELECT statement.
SELECT employee_id, first_name FROM employees WHERE department = 'IT' UNION SELECT employee_id, first_name FROM employees WHERE department = 'Finance';
The "UNION" operator is used to combine the result sets of two "SELECT" statements.
The resulting set will contain unique combinations of "employee_id" and "first_name" from the 'IT' department and the 'Finance' department.