SQLite UNION statement

The SQLite UNION statement combines datasets into one dataset. You can use the SQLite UNION statement to e.g. combine two query results into one dataset.

Here is an example:

SELECT name
  FROM coredata
UNION
SELECT address
  FROM locationdata;

Above data combines the name column data from coredata table with the address column data from locationdata table.

Note that duplicates are not contained by the resulting dataset. The example below demonstrates this.

CREATE TABLE table1(
    name TEXT
);
 
INSERT INTO table1(name)
VALUES("Frida"),("Sam"),("Eric");
 
CREATE TABLE table2(
    name TEXT
);
INSERT INTO table2(name)
VALUES("Luis"),("Lenny"),("Sam");

SELECT name
  FROM table1
UNION
SELECT name
  FROM table2;

Above SQLite code returns the following query result: “Frida”,”Sam”,”Eric”,”Luis”,”Lenny”.