SQL INNER JOIN
Posted on
< Previous Next >
SQL INNER JOIN is a type of SQL join that returns only the rows from both tables that meet the specified join condition. In other words, it returns the rows where there is a match between the joining columns of both tables.
INNER JOIN Syntax
SELECT column1, column2, …
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
For Example,
SELECT s.name, sub.id
FROM student s
INNER JOIN exam e
ON s.id = e.student_id
INNER JOIN subject sub
ON e.subject_id = sub.id;
OUTPUT

In this above example,
We are selecting the name column from the student table and the subject column from the subject table, where there is a match between the student ID in the student table and the student ID in the exam table, and between the subject ID in the exam table and the subject ID in the subject table. The INNER JOIN ensures that we only get rows where there is a match in all three tables. The result of this query would be a table with the names of all students who took an exam, along with the subject of the exam they took.
< Previous Next >