Databricks Data Engineer Associate Question 183
Single answerYou are working on a Databricks SQL query to analyze sales data. You have two tables: customers and orders. The customers table contains the columns customer_id and customer_name, while the orders table contains the columns order_id, customer_id, and order_amount. You execute the following query:
SELECT c.customer_name, o.order_id, o.order_amount
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
What result will this query return?
- A
All customers who have placed at least one order, along with their order details.
- B
All customers who have not placed any orders.
- C
All orders where the customer information is missing.
- D
All customers and all their corresponding orders, including customers without orders.
Show answer and explanation
Correct answer: B
Explanation
The query uses a LEFT JOIN, which includes all rows from the customers table and the matching rows from the orders table. The WHERE o.order_id IS NULL condition filters out rows where there is a match in the orders table, resulting in only customers who have not placed any orders being returned.
- A. Incorrect.
This is incorrect because the query filters out customers who have placed orders by using the
WHERE o.order_id IS NULLcondition. - B. Correct.
This is correct because the
LEFT JOINensures all customers are included, and theWHERE o.order_id IS NULLcondition filters for customers who do not have corresponding orders in theorderstable. - C. Incorrect.
This is incorrect because the query focuses on customers without orders, not orders with missing customer data.
- D. Incorrect.
This is incorrect because the query specifically filters for customers without orders, so it does not return all customers and their corresponding orders.