What is Join?

Posted by

To view Verified answers click on the button below.

Ans: An SQL Join is used to combine data from two or more tables, based on a common
field between them.

For example, consider the following two tables.

Student Table
EnrollNo StudentName Address
1000 geek1 geeksquiz1
1001 geek2 geeksquiz2
1002 geek3 geeksquiz3
StudentCourse Table

CourseID EnrollNo
1 1000
2 1000
3 1000
1 1002
2 1003

Following is join query that shows names of students enrolled in different courseIDs.

SELECT StudentCourse.CourseID, Student.StudentName
FROM StudentCourse
INNER JOIN Customers
ON StudentCourse.EnrollNo = Student.EnrollNo
ORDER BY StudentCourse.CourseID;

The above query would produce following result.
CourseID StudentName
1 geek1
1 geek2
2 geek1
2 geek3
3 geek1