Join orders to customer names

Return order_id, customers.name AS customer_name and amount for every order with a matching customer_id in customers. Keep separate orders even when their customer names or amounts are identical. Row order does not matter.

Difficulty: intermediate

Show hint

Use an INNER JOIN on customer_id. Qualify names that appear in both tables.

Tables and sample data

Each test starts with fresh tables. Result rows may be returned in any order. Column names and column order must match.

Sample data: customers
customer_id (integer)name (text)city (text)
1AshaKathmandu
2BenLondon
Sample data: orders
order_id (integer)customer_id (integer)amount (numeric)status (text)region (text)
10150paidEast
11270paidWest
12130pendingEast
Expected sample result
order_idcustomer_nameamount
10Asha50
11Ben70
12Asha30

Your solution

SQL · PostgreSQL

Results

PostgreSQL loads when you Run or Submit. Write one read-only SELECT or WITH query. Your query runs in this browser.

Back to Lesson