
Answer-first summary for fast verification
Answer: SELECT customer_id FROM customers EXCEPT SELECT order_customer_id FROM orders
Understanding the different Set Operators in Databricks SQL is key to solving this problem. Here's a brief overview: - **UNION ALL** – Retrieves all rows, including duplicates, from both queries. - **UNION** – Retrieves only distinct records from both queries, removing duplicates. - **MINUS or EXCEPT** – Retrieves all rows in the first `SELECT` statement not returned by the second `SELECT` statement. - **INTERSECT** – Retrieves only common rows returned by the two `SELECT` statements. - **INNER JOIN** – Selects records with matching values in both tables for the specified join column(s). The correct query uses `EXCEPT` to find customer IDs in the `customers` table not found in the `orders` table, thus identifying customers who haven't placed any orders.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
A data engineer is tasked with identifying customers who have not placed any orders on an e-commerce platform. They have two Delta tables: customers, containing details of registered customers, and orders, containing details of orders placed. Which query correctly identifies these customers?
A
SELECT customer_id FROM customers INTERSECT SELECT order_customer_id FROM orders
B
SELECT customer_id FROM customers UNION SELECT order_customer_id FROM orders
C
SELECT customer_id FROM customers c INNER JOIN orders o ON c.customer_id = o.order_customer_id
D
SELECT customer_id FROM customers UNION ALL SELECT order_customer_id FROM orders
E
SELECT customer_id FROM customers EXCEPT SELECT order_customer_id FROM orders
No comments yet.