Review Glossary FR

Size

Eyes

Finish a part in any dojo to unlock the next eyes.

Day 19 10 min

Joins

1 / 12 · ≈ 8 min left

The problem

The tea shop wants to email the customers who signed up but never ordered, and to thank the people who brought friends. The names are in one table and the orders in another, so each answer needs a join. You write them in psql, on PostgreSQL.

customers (id, name, city, referred_by): Ana Costa (Lyon), Ben Okafor (Paris, referred by Ana), Chloé Martin (Lyon, referred by Ana), Dmitri Ivanov (no city, referred by Ben), Emma Schulz (Lille) and Farid Benali (Paris). referred_by holds the id of another customer, or NULL.

orders (id, customer_id, status, ordered_at) holds 9 orders; Emma and Farid have none, and the guest order 107 has a NULL customer_id. order_items (order_id, product_id, quantity) links orders to products (id, name), and the name column of both customers and products is UNIQUE. Write the aliases c, o, oi, p and r without AS, as in customers c.