Select, Filter and Sort · Problem 6 of 118

Orders Still in Progress

MediumSelect, Filter and SortShop data

Operations wants the orders that still need attention.

Return the order_id, status and order_date of every order from 2026 (order dates from 2026-01-01 onward) whose status is neither 'cancelled' nor 'delivered'.

Hint 1

status NOT IN ('cancelled', 'delivered') is shorter than two <> tests.

Hint 2

Combine the two conditions with AND.

Reference solution

SELECT order_id, status, order_date
FROM orders
WHERE order_date >= '2026-01-01'
  AND status NOT IN ('cancelled', 'delivered');

"Neither A nor B" means "not A and not B". Writing status <> 'a' OR status <> 'b' is a classic mistake: every status differs from at least one of the two, so the condition is always true. NOT IN (...) expresses the idea directly and scales to longer lists.

Another way. Another query that returns the same result:

SELECT order_id, status, order_date
FROM orders
WHERE order_date >= '2026-01-01'
  AND status <> 'cancelled'
  AND status <> 'delivered';