logo

Question detail

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.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Structured Query Language (SQL)

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.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.