SQLite - How to export table data to CSV file

By xngo on June 12, 2019

The following command exports the data from the Employees table to a CSV file named employees.csv.

sqlite3 -header -csv Company.db "SELECT * FROM Employees LIMIT 4" > employees.csv
  • -header: Also export the column header name. If you don't want it, don't include in your command.
  • -csv: Export as CSV mode.
  • Company.db: Your database filename.
  • "SELECT * FROM Employees LIMIT 4": Your SQL query.
  • > employees.csv: Export to employees.csv file.

If you check the employees.csv file, you will see the following output.


About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.