Write selected rows to a CSV file.

Section: Move data in and out

Export a query result to CSV

text
text
.headers on
.mode csv
.once recent_users.csv
SELECT id, email, created_at FROM users ORDER BY created_at DESC LIMIT 100;
Explanation

Good for ad hoc reporting and support workflows.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Move data in and out
Import CSV with mode and separator
Set shell parsing options before import.
OpenIn sheettextsame section
Dump one table
Export only selected table schema and data.
OpenIn sheettextsame section
Load data from an SQL file
Execute inserts and DDL from a seed script.
OpenIn sheetbashsame section
Use the shell backup command
Create a backup from inside sqlite3.
OpenIn sheettext1 tag match
Create a compact backup with VACUUM INTO
Write a fresh copy of the database to a new file.
Run VACUUM
Rebuild the database file and reclaim free space.