Union All Operator in SQLite

SQLite Union All Operator
To combine the result set of two or more tables without any elimination, the SQLite UNION All Operator is used with the SELECT statement. It is mandatory to have the same number of fields in the result set in each SELECT statement.

Syntax:

SELECT expression1, expression2, ... expression_n  
FROM tables  
WHERE conditions
UNION ALL
SELECT expression1, expression2, ... expression_n  
FROM tables  
WHERE conditions;   

Example:
STUDENTS Table:

ID NAME SUBJECT
1 Tom German
2 Jerry Spanish
3 Bruno English

TEACHERS Table:

ID NAME SALARY SUBJECT
1 Jim 10000 Geology
2 John 20000 Geology
3 Watson 15000 Physics
4 Holmes 25000 Chemistry
5 Tony 30000 Physics
SELECT SUBJECT FROM STUDENTS  
UNION ALL
SELECT SUBJECT FROM TEACHERS;

Output:

SUBJECT
German
Spanish
English
English
Geology
French
Chemistry
Physics

Explanation:
In the above example, a union of the SUBJECT columns of the STUDENTS and the TEACHERS table is fetched without any elimination of the duplicate records.

Please Share