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.

firstname,lastname,salary,hired_on
"André",Doe,839391.98,2010-12-01
Nikki,Smith,105391.98,2018-11-21
"François",Brown,25391.98,2019-11-21
"Chloé",Anderson,95391.98,1990-09-13

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.