Which type of SQL JOIN automatically matches rows from two tables using…
2024
Which type of SQL JOIN automatically matches rows from two tables using columns that have the same name in both tables?
- A.
Inner Join
- B.
Cross Join
- C.
Self Join
- D.
Natural Join
- E.
Left Join
Attempted by 46 students.
Show answer & explanation
Correct answer: D
The correct answer is Natural Join.
A NATURAL JOIN automatically joins two tables on every column that has the same name (and a compatible data type) in both tables, without you writing an ON or USING clause. The database itself discovers the common column(s) at run time, matches rows where those columns are equal, and shows each shared column only once in the result. By default it behaves like an inner join, so only matching rows are returned.
For example, if EMPLOYEE and DEPARTMENT both contain a column named DEPT_ID, then EMPLOYEE NATURAL JOIN DEPARTMENT matches rows wherever the DEPT_ID values are equal, with no explicit join condition.
The other joins all need an explicit condition or behave differently: an INNER JOIN requires an ON/USING clause to state the matching columns; a CROSS JOIN produces the Cartesian product (every row paired with every row) and matches nothing; a SELF JOIN joins a table to itself; and a LEFT JOIN is an outer join that keeps all rows of the left table and still needs an explicit condition.