D8LooPFocus modeCODE WORKSPACE
Return order_id, buyer_id, status, and total_amount for paid orders only, newest first by created_at, limited to the 5 most recent.
Start from orders, filter to status = 'paid', then order by created_at DESC and LIMIT 5.
Sample input
| order_id | buyer_id | status | total_amount | created_at |
|---|---|---|---|---|
| 1011 | 2 | paid | 110 | 2026-02-02 09:00:00 |
| 1010 | 6 | paid | 640 | 2026-01-30 21:10:00 |
| 1007 | 3 | paid | 95 | 2026-01-22 14:46:00 |
| 1005 | 2 | paid | 540 | 2026-01-18 09:05:00 |
| 1002 | 3 | paid | 120 | 2026-01-12 10:02:00 |
| 1001 | 1 | paid | 80 | 2026-01-12 08:40:00 |
| 1003 | 4 | pending | 40 | 2026-01-13 11:15:00 |
Expected output
| order_id | buyer_id | status | total_amount |
|---|---|---|---|
| 1011 | 2 | paid | 110 |
| 1010 | 6 | paid | 640 |
| 1007 | 3 | paid | 95 |
| 1005 | 2 | paid | 540 |
| 1002 | 3 | paid | 120 |
Constraints
Select only the four named columns (no SELECT *). Keep only paid orders. Order by created_at descending and return at most 5 rows.
Expected skills
Choosing explicit columns, filtering with WHERE, ordering with ORDER BY, and sampling with LIMIT.
Run the SQL query to inspect preview rows.