Bootstrap FreeKB - SQLite - Select records from a table
SQLite - Select records from a table

Updated:   |  SQLite articles

The select command can be used to list the records in a table. In this example, the records in the users table in example.db are listed.

~]$ sqlite3 /path/to/example.db
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.

sqlite> select * from users;
1|2022-12-20 16:02:17|john.doe@example.com|itsasecret
2|2022-12-31 05:24:24|jane.doe@example.com|itsasecret

 

Or like this, as a oneliner command.

~]$ sqlite3 /path/to/example.db "select * from users"
1|2022-12-20 16:02:17|john.doe@example.com|itsasecret
2|2022-12-31 05:24:24|jane.doe@example.com|itsasecret

 

Almost always, I find it helpful to include .headers ON and .mode <mode> where mode is one of the following.

  • column or columns
  • csv
  • insert
  • html
  • line or lines
  • list
  • tabs
  • tcl
sqlite> .headers ON
sqlite> .mode columns
sqlite> select * from users;
id  date        username  password
--  ----------  --------  ----------
1   2022-12-20  john.doe  itsasecret
2   2023-01-01  jane.doe  itsasecret

 

Here is how to do this as a oneliner.

~]$ sqlite3 /path/to/example.db ".headers on" ".mode columns" "select * from users"
id  date        username  password
--  ----------  --------  ----------
1   2022-12-20  john.doe  itsasecret
2   2023-01-01  jane.doe  itsasecret

 

Limit can be used to limit the results.

sqlite> select * from users limit 1;
id  date        username  password
--  ----------  --------  ----------
1   2022-12-20  john.doe  itsasecret

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 7d307a in the box below so that we can be sure you are a human.