SQL Joins

SQL Joins is used to combine two or more tables based on their common columns between them.

Take a table Student:

StudentID StudentName City
15 Rahul Pathankot
16 Karan Pathankot
17 Ajay Pathankot


Now, Take another table Fees

FeesID StudentID StudentName Fees
1 15 Rahul 800
2 16 Karan 800
3 17 Ajay 800


Query



SELECT Student.StudentID, Student.StudentName, FeesID, Fees  FROM Student
INNER JOIN Fees ON StudentID.Fees=StudentID.Student;



Output

StudentID StudentName FeesID Fees
15 Rahul 1 800
16 Karan 2 800
17 Ajay 3 800


Different Types Of Joins



  • INNER JOIN : It returns record having match value.
  • LEFT OUTER JOIN : Returns all records from the left table, and the matched records from the right table.
  • RIGHT OUTER JOIN : Returns all records from the right table, and the matched records from the left table.
  • FULL OUTER JOIN : Returns all records when there is a match in either left or right table.

Back To Top