TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

SQLite Union

SQLite Union with history, features, advantages, installation, commands, syntax, datatypes, operators, expressions, databases, table, crud operations, clauses, like, glob, limit, and clause, advance sqlite

<< Back to SQLITE

SQLite Union Operator

SQLite UNION Operator is used to combine the result set of two or more tables using SELECT statement. The UNION operator shows only the unique rows and removes duplicate rows.

While using UNION operator, each SELECT statement must have the same number of fields in the result set.

Syntax:

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

Example:

We have two tables "STUDENT" and "DEPARTMENT".

Sqlite Union operator 1

The "STUDENT" table is having the following data:

Sqlite Union operator 2

The "DEPARTMENT" table is having the following data:

Sqlite Union operator 3

Example1: Return Single Field

This simple example returns only one field from multiple SELECT statements where the both fields have same data type.

Let's take the above two tables "STUDENT" and "DEPARTMENT" and select id from both table to make UNION.

SELECT ID FROM STUDENT
UNION
SELECT ID FROM DEPARTMENT; 

Output:

Sqlite Union operator 4

Example2: Union with Inner and Outer Join

Let's take the above two tables "STUDENT" and "DEPARTMENT" and make an inner join and outer join according to the below conditions along with UNION Clause:

SELECT EMP_ID, NAME, DEPT FROM STUDENT JOIN DEPARTMENT
ON STUDENT.ID = DEPARTMENT.EMP_ID
UNION
SELECT EMP_ID, NAME, DEPT FROM STUDENT LEFT OUTER JOIN DEPARTMENT
ON STUDENT.ID = DEPARTMENT.EMP_ID; 

Output:

Sqlite Union operator 5
Next TopicSQLite Union All




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf