The Tables of Pixel Shop

Pixel Shop's database has five tables. You know two of them already:

  • games – the games the shop sells.
  • customers – the shop's customers: their name, email and city, the day they joined (joined), and referred_by, the ID of the customer who recommended the shop to them.
  • orders – one row for each order: who placed it (customer_id), when (ordered_at), and its status: paid, or refunded when the customer got their money back.
  • order_items – what each order had in it: the order (order_id), the game (game_id), how many copies (quantity) and the price the customer paid for one copy. In a sale, that's less than the game's price.
  • reviews – the reviews of games: the game, the customer, the stars from 1 to 5, and a comment.

The tables games, customers and orders have a column id with a number that identifies each row: no two rows of a table have the same one. Such a column is the table's primary key. Other tables use it to point at a row. Here's the first order:

idcustomer_idordered_atstatus
112024-01-20paid

Its customer_id is 1, so it was placed by the customer whose id is 1: Emma Clark. And the rows of order_items whose order_id is 1 say what she bought:

order_idgame_idquantityprice
13120
1615

The games 3 and 6, Moon Farm and Cube Logic. A column that points at the rows of another table, such as customer_id or game_id, is a foreign key. Thanks to them, the shop keeps each customer and each game just once, however many orders there are. For now, you can follow them by hand in the Tables tab; later, you'll learn to combine tables in one query.

Some cells say NULL. That's not a text, it means that there's no value: the shop doesn't know Ava Green's city, Robot Rebellion and Mystery Manor haven't come out yet, and nobody recommended the shop to Emma Clark. NULL isn't zero or empty text, and it has rules of its own, which you'll learn soon.

Instructions

Show the whole table order_items.

order_idgame_idquantityprice
13120
1615
…………

Below it, show the stars and the comment of every review. Some reviews have no comment:

starscomment
5Best RPG I have played in years!
4Great story, a bit long.
5NULL
……

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

7/8