Advanced Joins: Payments With Order and Customer Info

SQL coding challenge · Difficulty: medium · Topic: Joins · +100 XP

Problem

The accounting team needs to reconcile payments against orders. For each payment, show the amount, the order it's linked to, and the customer name.

Tables

Table: Customers

| customer_id | name | city |
| --- | --- | --- |
| 1 | Atul | Delhi |
| 2 | Prince | Mumbai |
| 3 | Mohit | Bangalore |
| 4 | Rahul | Chennai |

Table: Orders

| order_id | customer_id | order_date |
| --- | --- | --- |
| 101 | 1 | 2024-05-01 |
| 102 | 1 | 2024-05-05 |
| 103 | 2 | 2024-05-03 |
| 104 | 3 | 2024-05-07 |

Table: Payments

| payment_id | order_id | amount |
| --- | --- | --- |
| 201 | 101 | 2500.00 |
| 202 | 102 | 1250.00 |
| 203 | 103 | 3000.00 |
| 204 | 104 | 1750.00 |
| 205 | 106 | 2200.00 |

Expected Output

| payment_id | order_id | name | amount |
| --- | --- | --- | --- |
| 201 | 101 | Atul | 2500.00 |
| 202 | 102 | Atul | 1250.00 |
| 203 | 103 | Prince | 3000.00 |
| 204 | 104 | Mohit | 1750.00 |
| 205 | NULL | NULL | 2200.00 |

What this SQL challenge teaches you

“Advanced Joins: Payments With Order and Customer Info” is a medium-level SQL challenge focused on Joins. Working through it gives you hands-on practice with Multiple JOINs, LEFT JOIN, NULL — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.

Concepts covered

How to approach it

If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:

  1. Your result should return: payment_id, amount, order_id, customer_name.
  2. Order the output payment_id ascending.
  3. Compare your output to the Expected Output — the columns, values and row order must match exactly.

Where this comes up

Variations of this problem have been reported in interviews at Databricks, Netflix, Cloudflare. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.

How to practise it on PySpark.in

Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.

Related SQL challenges

Frequently asked questions

Do I need to install Spark or a database to solve this?

No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.

Is this challenge free?

Yes - the problem, the sample dataset, the hints and unlimited test runs are free.

What level is it?

It is rated medium and covers Joins.

Solve this challenge free on PySpark.in