Joins in SQLite

SQLite Joins

To combine records from two or more tables in a database, the SQLite Joins are used. The common values in the mentioned fields from the tables are fetched and displayed as the result.

 

Types of SQLite Joins:

SQLite supports three types of Joins, including,

  • SQLite INNER JOIN
  • SQLite OUTER JOIN
  • SQLite CROSS JOIN

Example:
STUDENTS Table:

STUDENT_ID STUDENT_NAME STUDENT_SUBJECT
1 Tom French
2 Jerry Physics
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 ID, STUDENT_NAME, NAME, SUBJECT
FROM STUDENTS 
INNER JOIN TEACHERS  
ON STUDENTS.STUDENT_SUBJECT = TEACHERS.SUBJECT;

Output:

ID STUDENT_NAME NAME SUBJECT
3 Tom Watson French
5 Jerry Tony Physics
1 Bruno Jim English

Explanation:
In the above example, the records from the ID, NAME, and the SUBJECT Columns of the TEACHERS table and the STUDENT_NAME column of the STUDENTS table is fetched and joined where the value of the STUDENT_SUBJECT column of the STUDENTS table is equal to the SUBJECT column of the TEACHERS table.

Please Share