0% found this document useful (0 votes)
22 views7 pages

6.SQL Join

The document explains SQL JOIN statements used to combine data from multiple tables based on common fields, detailing four types: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Each type is described with its function and example queries demonstrating their usage. INNER JOIN selects matching rows, LEFT JOIN includes all rows from the left table, RIGHT JOIN includes all rows from the right table, and FULL JOIN combines results from both sides.

Uploaded by

sharmasudip010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

6.SQL Join

The document explains SQL JOIN statements used to combine data from multiple tables based on common fields, detailing four types: INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Each type is described with its function and example queries demonstrating their usage. INNER JOIN selects matching rows, LEFT JOIN includes all rows from the left table, RIGHT JOIN includes all rows from the right table, and FULL JOIN combines results from both sides.

Uploaded by

sharmasudip010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL JOIN

SQL Join statement is used to combine data or rows from two or more tables
based on a common field between them. Different types of Joins are as follows:

 INNER JOIN
 LEFT JOIN
 RIGHT JOIN
 FULL JOIN

How to use SQL join or SQL Inner Join?

Consider the two tables below:


A. INNER JOIN

The INNER JOIN keyword selects all rows from both the tables as long as the
condition is satisfied.

Note: We can also write JOIN instead of INNER JOIN. JOIN is same as INNER JOIN.

SELECT StudentCourse.COURSE_ID, Student.NAME, Student.AGE FROM


Student INNER JOIN StudentCourse
ON Student.ROLL_NO = StudentCourse.ROLL_NO;
B. LEFT JOIN

 This join returns all the rows of the table on the left side of the join and
matches rows for the table on the right side of the join.

 For the rows for which there is no matching row on the right side, the
result-set will contain null.

 LEFT JOIN is also known as LEFT OUTER JOIN.

Note: We can also use LEFT OUTER JOIN instead of LEFT JOIN, both are the same.

SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
LEFT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
C. RIGHT JOIN

 RIGHT JOIN is similar to LEFT JOIN.

 This join returns all the rows of the table on the right side of the join and
matching rows for the table on the left side of the join.

 For the rows for which there is no matching row on the left side, the result-set
will contain null.

 RIGHT JOIN is also known as RIGHT OUTER JOIN.

Note: We can also use RIGHT OUTER JOIN instead of RIGHT JOIN, both are the
same.

Example Queries(RIGHT JOIN):

SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
RIGHT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
D. FULL JOIN

 FULL JOIN creates the result-set by combining results of both LEFT JOIN and
RIGHT JOIN.

 The result-set will contain all the rows from both tables.

 For the rows for which there is no matching, the result-set will
contain NULL values.

Example Queries(FULL JOIN):

SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
FULL JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;

You might also like