SQLite CLI and Shell Cheatsheet/Write the next query result to a file

Send one result set to a file without changing subsequent output.

Section: Output, import, and export

Write the next query result to a file

text
text
.once users.csv
Explanation

Combine with `.mode csv` and a `SELECT` statement to export a query result.

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 Output, import, and export
Show column headers
Enable headers in tabular output.
OpenIn sheettextsame section
Use aligned column output
Render query results in a readable table.
OpenIn sheettextsame section
Export rows as CSV
Switch output mode to CSV.
OpenIn sheettextsame section
Import a CSV file into a table
Load rows from CSV using the shell importer.
OpenIn sheettextsame section
Execute SQL from a file
Run a script inside the shell.
OpenIn sheettextsame section
Dump the full database as SQL
Export schema and data as executable SQL.
OpenIn sheettextsame section