Exam-style question
Try this first
A database has an Order table with CustomerID and an Item table with ItemID and Description. The Order table also contains ItemID. Write an SQL statement that retrieves each OrderID and the corresponding item Description by joining the tables. Explain how the tables are matched.
Model answer
What a good answer should say
- SELECT Order.OrderID, Item.Description FROM Order JOIN Item ON Order.ItemID = Item.ItemID;
Explanation
Why this works
The statement retrieves OrderID from Order and Description from Item. JOIN combines rows from the two tables, and the ON clause matches rows where the ItemID in Order equals the ItemID in Item.
Common mistake
No common mistake is linked to this question yet.
