Identify the Join Type from SQL Consider the SQL statement: SELECT CUSTOMER_T.CUSTOMER_ID, ORDER_T.CUSTOMER_ID, NAME, ORDER_ID FROM CUSTOMER_T, ORDER_T WHERE CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID Which join type best describes this query?
-
AEqui-join
-
BNatural join
-
COuter join
-
DCartesian join
-
ECross apply
Answer
Correct Answer: Equi-join
Explanation
Introduction:Determining the join type from SQL syntax is a key reading skill. The classic comma-join with a WHERE clause equating keys is an inner equi-join, even though it does not use the explicit JOIN ... ON syntax introduced in later SQL standards.
Given Data / Assumptions:
- Two tables: CUSTOMER_T and ORDER_T.
- Join condition: CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID.
- Traditional comma-separated FROM clause is used with a WHERE predicate.
Concept / Approach:An equi-join is any join where the join predicate is equality on one or more columns. The query uses a WHERE clause with equality on CUSTOMER_ID, producing only matching rows from both tables, which is the definition of an inner equi-join. A natural join would match identically named columns implicitly and is not shown here. An outer join would include unmatched rows, which this query does not do. A Cartesian join has no join predicate and returns the product of rows from both tables.
Step-by-Step Solution:Observe the equality predicate on CUSTOMER_ID in the WHERE clause.Conclude that only rows with equal keys from both tables are returned.Classify this as an inner equi-join due to the equality condition.Exclude outer join or Cartesian join because their behaviors do not match this predicate.
Verification / Alternative check:Rewrite using explicit syntax: SELECT ... FROM CUSTOMER_T INNER JOIN ORDER_T ON CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID; The result is the same, confirming the equi-join classification.
Why Other Options Are Wrong:
- Natural join is implicit on identically named columns and is not explicitly used here.
- Outer join would retain non-matching rows, which the WHERE equality eliminates.
- Cartesian join lacks a join predicate entirely.
- Cross apply is a vendor-specific lateral join construct, not applicable here.
Common Pitfalls:Assuming that comma-join syntax always means a Cartesian product; once you add an equality predicate in WHERE, it becomes an inner equi-join.
Final Answer:Equi-join