What is Join?
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.
Following is join query that shows names of students enrolled in different courseIDs.
SELECT StudentCourse.CourseID,Student.StudentName FROM Student INNER JOIN StudentCourse ON StudentCourse.EnrollNo = Student.EnrollNo ORDER BY StudentCourse.CourseID
Note: INNER is optional above. Simple JOIN is also considered as INNER JOIN
The above query would produce following result.
What is the difference between inner join and outer join?
Outer Join is of 3 types
1) Left outer join
2) Right outer join
3) Full Join
1) Left outer join returns all rows of table on left side of join. The rows for which there is no matching row on right side, result contains NULL in the right side.
SELECT Student.StudentName, StudentCourse.CourseID FROM Student LEFT OUTER JOIN StudentCourse ON StudentCourse.EnrollNo = Student.EnrollNo ORDER BY StudentCourse.CourseID
Note: OUTER is optional above. Simple LEFT JOIN is also considered as LEFT OUTER JOIN
2) Right Outer Join is similar to Left Outer Join (Right replaces Left everywhere)
3) Full Outer Join Contains results of both Left and Right outer joins.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- SQL | Join (Cartesian Join & Self Join)
- SQL | Join (Inner, Left, Right and Full Joins)
- Lossless Join and Dependency Preserving Decomposition
- DBMS | Join operation Vs nested query
- Difference between Relational Algebra and Relational Calculus
- Difference between Strong and Weak Entity
- Difference between Super Key and Candidate Key
- Difference between Normalization and Denormalization
- Difference between Primary and Candidate Key
- DBMS | Domain Relational Calculus
- Security Management System
- Attribute Subset Selection in Data Mining
- Differences between Views and Materialized Views in SQL
- What is Unstructured Data?