CodesJava

Easy learning with example program codes

Inner Join in SQLite

SQLite Inner Join
To combine all rows from multiple tables, the SQLite Inner join is used. However, it joins only those rows where the join condition is satisfied. It is the simplest, most popular and the default type of Join in SQLite.

Syntax 1:

SELECT columns
FROM table_1 
INNER JOIN table_2 
ON conditions

Syntax 2:

SELECT columns
FROM table_1  
JOIN table2 
USING ( column_1 ,... ) ...   

Syntax 3:

SELECT columns
FROM table_1   
NATURAL JOIN table2...  

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	English
2	John	20000	Geology
3	Watson	15000	French
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 follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status