JOIN : Sql Join are used to combine rows from two or more tables.
Different SQL JOINs
- Inner Join : Return rows when there is at least one match in both tables.
- Left Outer Join : Return all rows from the left table, even if there are no matches in the right table.
- Right Outer Join : Return all rows from the right table, even if there are on matches in the left table.
- Full Outer Join : Return rows when there is a match in the one of the table.
SELECT * FROM Student
2nd Table –
SELECT * FROM Course
1) Inner Join : Return rows when there is at least one match in both tables.
INPUT—
SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
Student.Email, Course.Code, Course.Name
FROM Student
INNER JOIN Course ON Student.CourseId=Course.Id;
OUTPUT –
2) Left Outer Join : Return all rows from the left table, even if there are no matches in the right table.
INPUT—
SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
Student.Email, Course.Code, Course.Name
FROM Student
LEFT OUTER JOIN Course ON Student.CourseId=Course.Id;
OUTPUT—
3) Right Outer Join : Return all rows from the right table, even if there are on matches in the left table.
INPUT –
SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
Student.Email, Course.Code, Course.Name
FROM Student
RIGHT OUTER JOIN Course ON Student.CourseId=Course.Id;
OUTPUT—
4) Full Outer Join : Return rows when there is a match in the one of the table.
INPUT—
SELECT Student.Id, Student.Name, Student.City, Student.Mobile,
Student.Email, Course.Code, Course.Name
FROM Student
FULL OUTER JOIN Course ON Student.CourseId=Course.Id;
OUTPUT—
No comments:
Post a Comment