Skip to content

Bug Report for sql-customers-bought-a-b-not-c #5625

@sidAKAsadiq

Description

@sidAKAsadiq

Bug Description

When using a LEFT JOIN with a subquery as the left table, the output display
incorrectly renders the left table's customer_id as null instead of its
actual value.

Steps to Reproduce

  1. Go to: https://neetcode.io/problems/sql-customers-bought-a-b-not-c
  2. Run the following query:

SELECT o12., o3.
FROM (
SELECT o1.customer_id
FROM (SELECT * FROM orders WHERE product_name = 'A') AS o1
INNER JOIN (SELECT * FROM orders WHERE product_name = 'B') AS o2
ON o1.customer_id = o2.customer_id
) AS o12
LEFT JOIN (SELECT * FROM orders WHERE product_name = 'C') AS o3
ON o12.customer_id = o3.customer_id;

Expected Output

customer_id (o12) | order_id | customer_id (o3) | product_name
1 | 104 | 1 | C
3 | null | null | null

Actual Output

customer_id | order_id | customer_id | product_name
1 | 104 | 1 | C
null | null | null | null

Impact

The left side of a LEFT JOIN should never be null. This misleading display
causes confusion about query correctness, as the actual JOIN logic works
correctly when further joined with the customers table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions