I have 2 tables like this:
[people1]:
|First Name*| Last Name*|
| | |
|Martin | Green |
|Peter | Blue |
[people2]:
|Name* |
| |
|Linda |
|Jane Yellow|
and what my desired output of a SQL command is:
|Name |
| |
|Martin Green |
|Peter Blue |
|Linda |
|Jane Yellow |
I cannot change the structure of the 2 tables.
It helps to know the database — string concatenation is not consistent.
For SQL Server and MySQL:
For Oracle, PostgreSQL:
The double pipe is now the ANSI means of concatenating strings – MySQL might support it if strict ANSI is enabled.
The
UNIONoperator allows to combine more than one query, and it removes duplicates.UNION ALLdoes not remove duplicates, and is faster for it. The number of columns in all the queries UNIONed need to be the same, and data types should match at each position.