Schema and sample data
| order_id | customer_id | order_date | amount |
|---|---|---|---|
| 1001 | 7 | 2026-01-05 | 250.00 |
| 1002 | 3 | 2026-01-06 | 99.50 |
| 1003 | 7 | 2026-01-09 | 100.00 |
| 1004 | 5 | 2026-01-11 | 480.75 |
| 1005 | 2 | 2026-01-14 | 100.01 |
| 1006 | 3 | 2026-01-18 | 175.25 |
Show setup SQL (copy to run)
CREATE TABLE Orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
amount DECIMAL(10,2) NOT NULL
);
INSERT INTO Orders (order_id, customer_id, order_date, amount) VALUES
(1001, 7, '2026-01-05', 250.00),
(1002, 3, '2026-01-06', 99.50),
(1003, 7, '2026-01-09', 100.00),
(1004, 5, '2026-01-11', 480.75),
(1005, 2, '2026-01-14', 100.01),
(1006, 3, '2026-01-18', 175.25);
From the Orders table, return the order_id and amount of every order whose amount is greater than 100. Sort the result by amount from highest to lowest.
Expected result
| order_id | amount |
|---|---|
| 1004 | 480.75 |
| 1001 | 250.00 |
| 1006 | 175.25 |
| 1005 | 100.01 |
Show hint
Use a WHERE clause to keep only the rows above the threshold, then ORDER BY to sort them. Note that "greater than 100" is a strict comparison, so the order that is exactly 100.00 should not appear in the result.
Try to write the query yourself before you open this.
Show solution and explanation
SELECT order_id, amount
FROM Orders
WHERE amount > 100
ORDER BY amount DESC;
The WHERE amount > 100 filter runs first and keeps only the rows whose amount is strictly greater than 100. Order 1003 is exactly 100.00 and order 1002 is 99.50, so both are dropped. Order 1005 at 100.01 does clear the bar, which is a good reminder that a strict greater-than (not >=) still admits any value just above the threshold.
ORDER BY amount DESC then sorts the four surviving rows from highest to lowest amount. Without DESC the default sort direction is ascending. Because of the logical query processing order, WHERE is applied before ORDER BY, so the filter shrinks the set before it is sorted.
Only the two requested columns are selected. A common mistake here is to reach for SELECT *, but naming just order_id and amount keeps the output predictable and lets an index cover the query. See why to avoid SELECT star.