Skip to content
RED SAGSkills

Products Sold but Never Returned

Find active products (discontinued = 0) that were ordered at least once in 2025 (by orders.order_date) and have never been returned (no row in returns for that product, at any date). Some returns rows have a NULL product_id because the item could not be identified; those rows refer to no product.

Return columns product_id, name. Row order does not matter.

Schema

CREATE TABLE products (
  product_id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  discontinued INTEGER NOT NULL
);
CREATE TABLE orders (
  order_id INTEGER PRIMARY KEY,
  order_date TEXT NOT NULL
);
CREATE TABLE order_items (
  order_id INTEGER NOT NULL,
  product_id INTEGER NOT NULL,
  quantity INTEGER NOT NULL
);
CREATE TABLE returns (
  return_id INTEGER PRIMARY KEY,
  order_id INTEGER NOT NULL,
  product_id INTEGER
);

Sample data

products

product_idnamediscontinued
1Trail Shoes0
2Running Socks0
3Hydration Vest0
4Old Cap1
5Headlamp0

orders

order_idorder_date
1002025-03-01
1012025-07-15
1022026-01-10

order_items

order_idproduct_idquantity
10011
10023
10131
10142
10251

returns

return_idorder_idproduct_id
11001
Hint 1

EXCEPT removes from the first query every row that appears in the second.

Hint 2

NOT IN (subquery) returns no rows at all if the subquery contains a NULL. EXCEPT or NOT EXISTS avoids that.

Good practice for: Data Analyst, Backend Developer, Database Administrator, Business Analyst

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.