
Answer-first summary for fast verification
Answer: a1, 200 a3, NULL a4, 300
In a LEFT JOIN, all records from the left table (favorite_stores) are included, and only the matching records from the right table (sales) are added. In this case, 'a1' and 'a4' from the left table match with 'a1' and 'a4' from the right table, so these matching records are fetched. Additionally, 'a3' from the left table is included, and since 'a3' has no corresponding store_id in the right table, the sale_amount for 'a3' will be NULL. Therefore, the result includes 'a1, 200', 'a3, NULL', and 'a4, 300'.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
A data engineer needs to analyze customer preferences and store sales by combining information from two distinct tables. The first table, named favorite_stores, captures the relationship between customers and their preferred stores. The second table, named sales, records the sales amounts associated with each store. Below are the tables used in this task:
Table 1: favorite_stores
| store_id | customer_id |
|---|---|
| a1 | c1 |
| a3 | c2 |
| a4 | c3 |
Table 2: sales
| store_id | sale_amount |
|---|---|
| a1 | 200 |
| a2 | 150 |
| a4 | 300 |
The data engineer executes the following SQL query to perform a left join between these tables:
SELECT favorite_stores.store_id, sales.sale_amount FROM favorite_stores LEFT JOIN sales ON favorite_stores.store_id = sales.store_id;
What will be the result set returned by this SQL query?
A
a1, 200 a2, NULL a4, 300
B
a1, 200 a3, NULL a4, 300
C
a1, 200 a3, 150 a4, 300
D
a1, 200 a4, 300