Skip to content

Instantly share code, notes, and snippets.

@rohitfarmer
Last active September 19, 2022 19:02
Show Gist options
  • Save rohitfarmer/83a9ecf987c501e371939c576fa5588d to your computer and use it in GitHub Desktop.
Save rohitfarmer/83a9ecf987c501e371939c576fa5588d to your computer and use it in GitHub Desktop.
Sqlite commands

My SQLite Cookbook

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

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment