77
MariaDB UNION Operator
In MariaDB database, UNION Operator is used to combine the result sets of two or more SELECT statements. It removes duplicate rows between the various SELECT statements.
Syntax:
Note: Each SELECT statement within the UNION operator must have the same number of fields in the result sets with similar data types.
Return Single Field using UNION Operator
Let’s take an example of MariaDB UNION Operator that returns one field from multiple SELECT statements. (Both tables having a same common field).
We have two tables “Student” and “Students”.
Student Table:
Students Table:
Output:
It shows the student_name from both table where duplicates names are removed.
UNION Operator with ORDER BY Clause
Use UNION operator with ORDER BY clause to retrieve multiple columns from both table.
Output:
Next TopicMariaDB Union All Operator