SQLite Union Operator
To combine the result set of two or more tables, the SQLite UNION Operator is used with the SELECT statement. The result, however, includes only the unique rows and all duplicate rows are eliminated. It is mandatory to have the same number of fields in the result set in each SELECT statement.
SELECT expression1, expression2, ... expression_n FROM tables WHERE conditions UNION SELECT expression1, expression2, ... expression_n FROM tables WHERE conditions;
STUDENT_ID STUDENT_NAME STUDENT_SUBJECT 1 Tom German 2 Jerry Spanish 3 Bruno English
ID NAME SALARY SUBJECT 1 Jim 10000 English 2 John 20000 Geology 3 Watson 15000 French 4 Holmes 25000 Chemistry 5 Tony 30000 Physics
SELECT SUBJECT FROM STUDENTS UNION SELECT SUBJECT FROM TEACHERS;
SUBJECT German Spanish English Geology French Chemistry Physics
In the above example, a union of the SUBJECT columns of the STUDENTS and the TEACHERS table is fetched.