SQL Practice Problem #003

Show newest orders first

List all orders so the most recent order appears first.

Problem

Task

List all orders so the most recent order appears first.

Schema

Table Schema

orders(id, customer_id, total_amount, ordered_at)

Input

Sample Data

idcustomer_idtotal_amountordered_at
101158.52026-03-02
102319.992026-03-09
10321042026-02-18

Output

Expected Output

idcustomer_idtotal_amountordered_at
102319.992026-03-09
101158.52026-03-02
10321042026-02-18

Answer

Check Your Solution

Show Answer and Explanation

Correct Answer

SELECT *
FROM orders
ORDER BY ordered_at DESC;

Explanation

ORDER BY sorts the final result set. DESC means descending order, so later dates are placed before earlier dates.

Common Mistakes

  • Using ASC, which puts the oldest order first.
  • Sorting by id instead of ordered_at.
  • Assuming the database returns rows in insertion order without ORDER BY.

Concepts

Related Concepts

ORDER BY DESC Sorting Dates

Next practice

Related Problems