Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join Across Three Tables

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Join Across Three Tables. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a SQL join query using three tables.

Use the provided customers, orders, and payments tables. Return every order with its customer name and payment status, including orders that have no matching payment record.

Output

  1. One row per order, with columns customer_name, order_id, order_status, and payment_status
  2. Include all orders and use NULL when no payment exists
  3. Order by order_id ascending

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
emailVARCHAR(255)Customer email address
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
customer_idINTCustomer who placed the order
order_statusVARCHAR(30)Current order status
order_dateDATEDate the order was created
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
order_idINTOrder associated with the payment
payment_statusVARCHAR(30)Current payment status
amountNUMERIC(10,2)Payment amount
Tablescustomersorderspayments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results