SQL Oracle PHP Java JSP JDBC MORE

SQL JOIN with Example


To select data from two or more table SQL join is used.

There are the different types of the JOINs in SQL:
  • INNER JOIN: Select the records that have matching values in both tables
  • LEFT JOIN: Select all records from the left table, and the matched records from the right table
  • RIGHT JOIN: Select all records from the right table, and the matched records from the left table
  • FULL JOIN: Select all records when there is a match in either left or right table

Inner join

left join

Right join

Full join

SQL JOIN Example

Assume that we have two table

students_data table

RollNo Name Address ContactNo
1 Divya Mumbai 9437911966
2 Hritika Pune 9887454545
3 Amit Delhi 7766888888

students_mark table

RollNo Mark Grade
1 95 O
2 85 A
3 65 B

Example

SELECT students_data.RollNo, students_data.Name, students_data.Address, students_mark.Marks, students_mark.Grade
FROM students_data
INNER JOIN students_mark ON students_data.RollNo = students_mark.RollNo;
RollNo Name Address Mark Grade
1 Divya Mumai 95 O
2 Hritika Pune 85 A
3 Amit Delhi 65 B