Correct:
--> SELECT e.EmpName FROM Employees e INNER JOIN Employees m ON e.EmpID = m.ManagerID;
--> SELECT e.EmpName FROM Employees e, Employees m WHERE e.EmpID = m.ManagerID;
Explanation:
Answer options B and C are correct.
Self-join is used to join a table to it. Each row of the table is joined to itself and to every other row of the table. The table name appears twice in the FROM clause, with two different aliases. The two aliases are treated as two different tables, and are joined to each other.
When performing self-join in ANSI syntax, the
JOIN .... ON
syntax should be used. The INNER keyword is optional.
Answer option D is incorrect. LEFT OUTER JOIN specifies a join between two tables. It returns all the rows from the left table in the join expression, and only those rows that meet the join condition from the right table. The syntax of LEFT OUTER JOIN is as follows:
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
Consider the following example, EMPLOYEE table and ORDER table:
P_ID |
LastName |
FirstName |
Address |
1 |
Harry |
David |
Storgata |
2 |
Steve |
Joseph |
California |
3 |
Peter |
Kari |
Toronto |
O_ID |
Order |
P_ID |
1 |
1023 |
1 |
2 |
2034 |
2 |
To join the EMPLOYEE table with the ORDER table containing EMPLOYEE if any, from the tables above, run the following command:
SELECT EMPLOYEE.LastName, ORDER.Order
FROM EMPLOYEE
LEFT JOIN ORDER
ON EMPLOYEE.P_Id=ORDER.O_Id
ORDER BY EMPLOYEE.LastName
The output of the command will appear as:
LastName |
Order |
Harry |
1023 |
Steve |
2034 |
Peter |
|
Note: In some database, RIGHT JOIN is also called as RIGHT OUTER JOIN.
Answer option A is incorrect. There is no clause such as SELF JOIN in SQL.
Reference: http://www.liamdelahunty.com/tips/mysql_self_join.php