How would you join the customer and orders tables using the customer ID, and what information would you retrieve?
💡 Model Answer
To combine the customer and orders tables, you typically perform a join on the customer ID, which is the primary key in the Customer table and the foreign key in the Orders table. A common query is: SELECT c.CustomerID, c.Name, c.Email, o.OrderID, o.OrderDate FROM Customer c JOIN Orders o ON c.CustomerID = o.CustomerID. This returns a row for each order, enriched with the customer’s name and email. If you want to see all customers, including those without orders, use a LEFT JOIN. The resulting dataset will contain columns from both tables, allowing you to analyze order history per customer, calculate total spend, or identify inactive customers. The join leverages the PK/FK relationship to ensure that each order is matched to the correct customer, and it allows the database to use indexes on CustomerID for efficient lookups.
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