Self Join SQL

Multiple Choice Questions - Self Join SQL


1.A self join only joins a table to itself.

A) True
B) False

2.Common usecase to use self join is

A) to perform comparisons
B) report recursive relationships
C) find data inconsistencies
D) all of above

3."Using" clause can be used in a self join query.

A) True
B) False

4.To perform a self join, you need to use ...... to give each instance of the table a separate name.

A) having
B) inner join
C) alias
D) cross join

5.Table names EMPLOYEE with fields - EMPID, FirstName, LastName,  and ManagerID. The ManagerID is a reference to the EMPID of the employee's manager. If we want to find the names of all employees along with the names of their respective managers, we can use self join. 
Find out the correct query:

A)
Select E1.FirstName as EmployeeName, E2.FirstName as ManagerName From Employee E1 OUTER JOIN Employee E2 ON E1.ManagerID = E2.EMPID;

B)
 Select E1.FirstName as EmployeeName, E2.FirstName as ManagerName From Employee E1 SELF JOIN Employee E2 ON E1.ManagerID = E2.EMPID;

C)
Select E1.FirstName as EmployeeName, E2.FirstName as ManagerName From Employee E1 INNER JOIN Employee E2 ON E1.ManagerID = E1.EMPID;

D)
Select E1.FirstName as EmployeeName, E2.FirstName as ManagerName From Employee E1 INNER JOIN Employee E2 ON E1.ManagerID = E2.EMPID;

6.When you join a table to itself, you can list the same table only twice in the FROM clause.

A) True
B) False

7.An outer join can also be included in a self-join.

A) True
B) False

8.Self join is NOT of much help in case a table has records with hierarchical relationships between them.

A) True
B) False

9. An inner join is a join of two or more tables returning rows that satisfy the join condition, while a self join is a join of a table to itself.

A) True
B) False

10. A hierarchical join can be called a special case of self-join in which parent-child relationships within a table are "exploded" into a hierarchy.

A) True
B) False

Answers