QuestionQ136

Executing queries using Databricks SQL and Databricks SQL Warehouses

A data analyst must join the orders and customers tables using both customer_id and region_id as the join keys. The objective is to return only rows for which both values match across the two tables.

Which SQL query correctly carries out this join?

Choose two
  • A SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;
  • B SELECT * FROM orders INNER JOIN customers USING (customer_id, region_id);
  • C SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id AND orders.region_id = customers.region_id;
  • D SELECT * FROM orders LEFT JOIN customers ON orders.customer_id = customers.customer_id AND orders.region_id = customers.region_id;
Explanation

An inner join returns only matching rows. Both INNER JOIN ... USING (customer_id, region_id) and an INNER JOIN with equality conditions for both customer_id and region_id require the two key values to match in each table. The USING form is supported by many SQL dialects; the explicit ON form is the more universally recognizable expression of the same two-key join condition.

Community Discussion

No comments yet. Be the first to start the discussion!