INNER JOIN in Oracle

INNER Join is often called a SIMPLE Join as it is the simplest among all the kinds of joins and is also the most common one. When the join condition is met, the INNER Join returns all the rows from multiple tables.

Syntax:

SELECT expr_1, expr_2, ... expr_n  
FROM table_1   
INNER JOIN table_2  
ON join_predicate;

Parameters: expr_1, expr_2, … expr_n:It is used to specify the columns of the table which needs to be joined. table_1, table_2: It is used to specify the name of the tables from which the records need to be joined. join_predicate: It is used to specify the joining conditions to be strictly followed by the rows to be included in the result set.

Example: Students Table:

STUDENT_ID NAME AGE
1 Joy 20
2 Smiley 19
3 Happy 21
4 James 22
5 Bond 25

Teachers Table:

TEACHER_ID TEACHER_NAME TEACHER_AGE
101 James 30
102 Bond 25
103 Smith 40

Query:

SELECT students.student_id, students.student_name, teachers.teacher_id  
FROM students  
INNER JOIN teachers  
ON students.student_name = teachers.teacher_name

Output:

STUDENT_ID STUDENT_NAME TEACHER_ID
1 Joy 101
2 Smiley 102
STUDENT_ID	STUDENT_NAME	TEACHER_ID
1	        Joy	        101
2	        Smiley	        102

Explanation: The ‘students’ and the ‘teachers’ are the already existing tables. After the joining, the selected fields of the rows satisfying the conditions will be displayed as the result.

Please follow and like us:
Content Protection by DMCA.com