SQL Joins
SQL Joins
SELECT Student.NAME,Course.COURSE_ID
FROM Student
LEFT JOIN Course
ON Course.SID = Student.SID;
Student Course
Cont…
Output Of Left Join Above
Name CourseID
Ali Mohammed 1
Hirut Zerfu 2
Lia Maru 2
Ewnetu Zeberga 3
Memhiru Lukas 1
Course
Student
Cont…
SELECT Student.NAME,StudentCourse.COURSE_ID
FROM Student
RIGHT JOIN StudentCourse
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Name CourseID
Cont…
Output Of Above Right Join Query
Name CourseID
Ali Mohammed 1
Hirut Zerfu 2
Lia Maru 2
Ewnetu Zeberga 3
Memhiru Lukas 1
Null 4
Null 5
Null 4
4. Full Join
FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN.
The result-set will contain all the rows from both the tables. The rows for which there is no
matching, the result-set will contain NULL values.
SELECT table1.column1,table1.column2,table2.column1,....
FROM table1
FULL JOIN table2
ON table1.matching_column = table2.matching_column;
SELECT Student.NAME,Course.COURSE_ID
Student Course FROM Student
FULL JOIN Course
ON StudentCourse.ROLL_NO = Student.ROLL_NO;
Cont…
Name CourseID
Ali Mohammed 1
Hirut Zerfu 2
Lia Maru 2
Ewnetu Zeberga 4
Memhiru Lukas 5
Ethiopia Hager Null
Antony Kibru Null
Mesay Legesse Null
Null 4
Null 5
Null 4
Thank You!