Explain why using a LEFT JOIN on orders.customer_id = customers.id is the correct approach to combine orders and customers tables, and how it affects the result set.
š” Model Answer
A LEFT JOIN returns all rows from the left table (customers) and the matched rows from the right table (orders). If a customer has no orders, the order columns are NULL. This preserves every customer in the result, which is useful when you need to report on all customers, even those without activity. An INNER JOIN would drop customers with no matching orders. The LEFT JOIN also allows you to aggregate orders per customer using GROUP BY, ensuring that customers with zero orders can be represented with a total of NULL or 0 depending on how you handle NULLs.
This answer was generated by AI for study purposes. Use it as a starting point ā personalize it with your own experience.
š¤ Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI ā Starts at ā¹500