Find All Products That Are Out of Stock
SQL coding challenge · Difficulty: easy · Topic: Filtering · +50 XP
Problem
The inventory manager needs a list of all products that are completely sold out (stock = 0) so they can trigger restock purchase orders immediately.
Tables
Table: products
| product_id | product_name | category_id | stock_quantity | | --- | --- | --- | --- | | 1 | T-Shirt | 1 | 50 | | 2 | Jeans | 1 | 0 | | 3 | Sneakers | 2 | 30 | | 4 | Backpack | 2 | 0 | | 5 | Watch | 3 | 15 | | 6 | Sunglasses | 3 | 10 |
Table: categories
| category_id | category_name | | --- | --- | | 1 | Apparel | | 2 | Footwear | | 3 | Accessories |
Table: order_items
| item_id | product_id | quantity | unit_price | order_date | | --- | --- | --- | --- | --- | | 1 | 1 | 5 | 599 | 2024-05-01 | | 2 | 3 | 2 | 2499 | 2024-05-01 | | 3 | 2 | 3 | 1299 | 2024-05-02 | | 4 | 5 | 1 | 1499 | 2024-05-02 | | 5 | 3 | 4 | 2499 | 2024-05-03 | | 6 | 1 | 2 | 599 | 2024-05-03 | | 7 | 2 | 1 | 1299 | 2024-06-01 | | 8 | 4 | 2 | 899 | 2024-06-01 | | 9 | 5 | 4 | 1499 | 2024-06-02 |
Table: product_reviews
| review_id | product_id | rating | | --- | --- | --- | | 1 | 1 | 5 | | 2 | 1 | 4 | | 3 | 1 | 3 | | 4 | 2 | 4 | | 5 | 2 | 3 | | 6 | 3 | 5 | | 7 | 3 | 5 | | 8 | 4 | 2 | | 9 | 5 | 4 | | 10 | 5 | 5 |
Expected Output
| product_id | product_name | | --- | --- | | 2 | Jeans | | 4 | Backpack |
- Return:
product_id,product_name - Only products where
stock_quantity = 0 - Sort by
product_idascending
What this SQL challenge teaches you
“Find All Products That Are Out of Stock” is a easy-level SQL challenge focused on Filtering. Working through it gives you hands-on practice with WHERE, Stock check, Simple filter — 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
- WHERE
- Stock check
- Simple filter
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:
- Your result should return: product_id, product_name.
- Order the output product_id ascending.
- 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 Flipkart, Amazon, Myntra, Meesho. 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
- Filter Numeric Values Stored as Strings
- Filter Numeric Values Stored as Strings (SQL)
- Top 3 Products per Category
- Running Total Revenue
- Find Duplicate Emails
- Median Salary per Department
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 easy and covers Filtering.