Skip to main content

Command Palette

Search for a command to run...

LeetCode 183: Customers Who Never Order

LeetCode 183: Customers Who Never Order.

Updated
2 min read
LeetCode 183: Customers Who Never Order
V

I'm Varchasv, a Data Engineer working on enterprise data integration.

Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.

What I'm doing:

  • Solving 2 Leetcode problems daily (SQL + DSA).
  • Blogging about each problem.
  • Building in public.

My Goal - Land a better data engineering role by mid-2026.

Follow my journey !!

Date: January 19, 2026
Category: SQL
Time Taken: 10 minutes
Difficulty: Easy


Problem Statement

Write a solution to find all customers who never order anything.

Link: Customers Who Never Order


My Approach

Initial thought: Since we only need the names of customers who have never ordered, we can perform a left join on the customers and orders tables using customers.id = orders.customerId. Then, we can use the WHERE clause to find customers who have no order.id.

Final solution: A more efficient solution is to use NOT EXISTS with a subquery instead of a join. With this method, as soon as we find a customer with any orders, we can skip to the next customer. This saves time by not having to check all the data for each customer.

Why this works:
This works because as soon as we find any order.id for a customer, we stop looking for customers with no orders and move on to the next customer. This saves time.


Solution Code (Left Join)

SELECT c.name AS Customers
FROM Customers AS c
LEFT JOIN Orders AS o
ON c.id = o.customerId
WHERE o.id IS NULL

Solution Code (Optimized)

SELECT c.name AS Customers
FROM Customers AS c
WHERE NOT EXISTS (
    SELECT 1
    FROM Orders AS o
    WHERE o.customerId = c.id
)

Key Takeaway: Better optimization with NOT EXISTS.

Pattern: Anti Join / Anti-Semi Join

Mistakes I Made: There were no mistakes to mention. I simply wasn't aware of the optimized solution for this.

Series: 90 Days of Data Engineering Progress: 9/90 problems completed

Tags: #DEQuest #LeetCode #SQL #DataEngineering #BuildInPublic

90 Days of Data Engineering

Part 10 of 48

Solving 90 problems over 18 weeks. Daily posts Mon-Fri. Goal: Switch to development role.

Up next

LeetCode 347: Top K Frequent Elements

Understanding LeetCode 347: Find the Most Frequent K Elements