# ORDER BY & LIMIT — MySQL

Source: https://www.geekswithgeeks.com/en/mysql/sql-order-limit

> Sort results and cap how many rows come back.

## Sorting rows

`ORDER BY` sorts ascending (`ASC`, default) or descending (`DESC`).

```sql
SELECT name, created_at FROM customers
ORDER BY created_at DESC;
```

## Limiting rows

`LIMIT` caps the result count — useful for pagination with `OFFSET`.

```sql
SELECT name FROM customers
ORDER BY name
LIMIT 2 OFFSET 1;
```

Output:

```
name
Priya Nair
Rahul Mehta
```

## Always ORDER before LIMIT

Without `ORDER BY`, row order isn't guaranteed — always sort explicitly before using `LIMIT` for predictable results.
