The correct answer is option 1
EXPLANATION:
Self-Join:
A self-join is a join in which the table is joined with itself to get the appropriate results. In this case, it is necessary to ensure that the join statement defines an ALIAS name for both copies of the tables to avoid column ambiguity. Example:
TABLE COURSE |
Course_id | Course_Name | Pre_Course |
1 | C | NULL |
2 | C++ | 1 |
3 | Java | 2 |
4 | C# | 3 |
5 | VB.NET | 4 |
Query:
SELECT A. Coursename AS Course, B. Coursename AS Prerequisite_Course
FROM Course A, Course B
WHERE, A.Precourse = B.CourseID;
OUTPUT
Course | Prerequisite_Course |
C++ | C |
Java | C++ |
C# | Java |
VB.NET | Java |
Additional Information
Join:
Join operation is used to combine related tuples from two relations into single tuples. Join operation can be stated in terms of the Cartesian product followed by SELECT operation.
Join condition form: ANDAND……AND
Outer Join:
Let R and S be two relations on which join operation is performed. Consider R # S where # is an operator which could be left outer join, right outer join or full outer join. R is the left relation and S is the right relation. There are various variations of join operations such as equi-join, natural join, theta join, inner join, outer join.
Three forms of outer join as follows:
- The left outer join preserves tuples only in the relation R named before the left outer join operation.
- The right outer join preserves tuples only in the relation S named after the right outer join operation.
- The full outer join preserves tuples in R and S relations.
Equi Join:
Join operation with equality condition is known as equi-join.