SQL UNION

SQL UNION is used to accumulate the results of two SELECT statements.

The two SELECT statements must have the same number of columns with the same data type and in the same order.

UNION SQL syntax

SELECT column1, column2 FROM table1 UNION SELECT column1, column2 FROM table2

Example SQL UNION

table "people_business1"

pernamesurnamenickname
1HARRYCLARKWHITE
2HARRYSMITHJOHNSON
3JOHNBROWNANDERSON

table "people_business2"

pernamesurnamenickname
1PETERLEETENS
2HARRYSMITHJOHNSON
3WILLIAMJONESTAYLOR
SELECT name, surname FROM people_business1 UNION SELECT name, surname FROM people_business2
namesurname
HARRYCLARK
HARRYSMITH
JOHNBROWN
PETERLEE
WILLIAMJONES

The person 'HARRY SMITH JOHNSON' appears only once in the result, because the repeated rows will not appear.