Skip to content

SQLite

For general command line help
https://sqlite.org/cli.html

Access shell commands

To clear the terminal

.shell clear

Open/attach a database

sqlite3 database.db

Show tables

.tables

Select

Select everything from a table and order by desc

SELECT * FROM tweetscapture ORDER BY Date DESC;
SELECT * FROM tweetscapture ORDER BY date DESC LIMIT 1;

Count entries in a table

SELECT Count(*) FROM tweetscapture;

Calculate length of string in a column

SELECT Text, length(Text) FROM tweetscapture;

Python loop to iterate row wise in a database

for row in c.execute('SELECT * FROM stocks ORDER BY price'):
        print(row)