# DELETE

> Remove rows from a table
> Canonical HTML: https://tursodb.cn/docs/sql-reference/statements/delete/
> Upstream Source (MIT): https://docs.turso.tech/sql-reference/statements/delete
> Language: en

---
# DELETE

The `DELETE` statement removes rows from a table.

## Syntax

```sql
DELETE FROM table-name
[WHERE expression]
[RETURNING result-column [, result-column ...]]
[ORDER BY sort-expression [, sort-expression ...]]
[LIMIT expression [OFFSET expression]]
```

## Description

`DELETE` removes rows that match the `WHERE` condition. If no `WHERE` clause is provided, all rows in the table are deleted. The table itself is not removed; use [DROP TABLE](/docs/sql-reference/statements/drop-table/) to remove a table entirely.

### WHERE Clause

The `WHERE` clause restricts which rows are deleted. Only rows where the expression evaluates to true are removed. Without a `WHERE` clause, every row in the table is deleted.

```sql
DELETE FROM logs WHERE created_at < date('now', '-90 days');
```

### RETURNING Clause

The `RETURNING` clause causes the `DELETE` statement to return the values of each deleted row. The result columns can be any expression referencing the deleted row's columns.

```sql
DELETE FROM sessions
WHERE expires_at < datetime('now')
RETURNING session_id, user_id;
```

### ORDER BY and LIMIT

The `ORDER BY` and `LIMIT` clauses restrict which rows are deleted. `ORDER BY` determines the order in which rows are considered, and `LIMIT` caps the number of rows that are actually removed. `ORDER BY` requires `LIMIT` to be present.

```sql
DELETE FROM logs
ORDER BY created_at ASC
LIMIT 1000;
```

`LIMIT` accepts an optional `OFFSET` to skip a number of rows before applying the limit:

```sql
DELETE FROM logs
ORDER BY created_at ASC
LIMIT 500 OFFSET 100;
```

<div class="doc-callout doc-callout-info"><div class="doc-callout-title">NOTE</div><div class="doc-callout-body">

`ORDER BY` without `LIMIT` is not allowed on `DELETE` statements. If you need to delete all rows matching a condition in a specific order, provide a `LIMIT` value larger than the expected number of matching rows.

</div></div>


## Examples

### Delete rows matching a condition

```sql
CREATE TABLE tasks (id INTEGER PRIMARY KEY, title TEXT, completed INTEGER);
INSERT INTO tasks VALUES (1, 'Write docs', 1);
INSERT INTO tasks VALUES (2, 'Review PR', 0);
INSERT INTO tasks VALUES (3, 'Fix bug', 1);

DELETE FROM tasks WHERE completed = 1;

SELECT * FROM tasks;
-- 2|Review PR|0
```

### Delete with RETURNING

```sql
CREATE TABLE queue (id INTEGER PRIMARY KEY, payload TEXT, priority INTEGER);
INSERT INTO queue VALUES (1, 'job_a', 10);
INSERT INTO queue VALUES (2, 'job_b', 5);
INSERT INTO queue VALUES (3, 'job_c', 10);

DELETE FROM queue
WHERE id = (SELECT id FROM queue ORDER BY priority DESC, id ASC LIMIT 1)
RETURNING id, payload;
-- 1|job_a
```

### Delete the oldest rows with ORDER BY and LIMIT

```sql
CREATE TABLE events (id INTEGER PRIMARY KEY, message TEXT, created_at TEXT);
INSERT INTO events VALUES (1, 'startup', '2025-01-01');
INSERT INTO events VALUES (2, 'request', '2025-01-02');
INSERT INTO events VALUES (3, 'shutdown', '2025-01-03');
INSERT INTO events VALUES (4, 'startup', '2025-01-04');

DELETE FROM events
ORDER BY created_at ASC
LIMIT 2;

SELECT * FROM events;
-- 3|shutdown|2025-01-03
-- 4|startup|2025-01-04
```

## See Also

* [UPDATE](/docs/sql-reference/statements/update/) for modifying existing rows
* [INSERT](/docs/sql-reference/statements/insert/) for adding new rows
* [DROP TABLE](/docs/sql-reference/statements/drop-table/) for removing an entire table
* [SELECT](/docs/sql-reference/statements/select/) for querying data
