EvalFrame Technical Mock Interviews & Coding Practice

Customers Who Never Order

Easy · Database · SQL database problem · all problems

Write an SQL query to report all customers who never order anything. Return the result table in **any order**. ### Table: Customers | Column Name | Type | | :--- | :--- | | id | int | | name | varchar | `id` is the primary key column for this table. Each row contains the ID and name of a customer. ### Table: Orders | Column Name | Type | | :--- | :--- | | id | int | | customerId | int | `id` is the primary key column for this table. `customerId` is a foreign key of the ID from the Customers table. ### Example: **Input:** ```text Customers table: +----+-------+ | id | name | +----+-------+ | 1 | Joe | | 2 | Henry | | 3 | Sam | | 4 | Max | +----+-------+ Orders table: +----+------------+ | id | customerId | +----+------------+ | 1 | 3 | | 2 | 1 | +----+------------+ ``` **Output:** ```text +-----------+ | Customers | +-----------+ | Henry | | Max | +-----------+ ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(N + M)
  • Space complexity: O(N)

With indexed foreign keys, a hash join or merge join between Customers (N) and Orders (M) runs in linear time.

Follow-Up Questions Interviewers Ask About Customers Who Never Order

  • Why is LEFT JOIN ... WHERE right_id IS NULL preferred over NOT IN (SELECT customerId FROM Orders)?
    NOT IN fails or performs poorly if the subquery returns even a single NULL value because x NOT IN (..., NULL) evaluates to UNKNOWN. LEFT JOIN or NOT EXISTS is safer and optimizer-friendly.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.