Javatpoint Logo
Javatpoint Logo

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:

MariaDB Union all operator 1

Students Table:

MariaDB Union all operator 2

Output:

MariaDB Union all operator 3

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:

MariaDB Union all operator 4




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA