SQLite CRUD and SELECT Cheatsheet

High-value SELECT, INSERT, UPDATE, DELETE, UPSERT, ORDER BY, LIMIT, and filtering patterns for day-to-day SQLite development.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Read and filter rows

Select, sort, paginate, and project rows efficiently.

Select all columns

Read rows from a table.

sqlANYsqliteselect
sql
SELECT * FROM users;
Notes

Convenient interactively, but explicit column lists are often better for apps and stable contracts.

Select only needed columns

Return a smaller projection.

sqlANYsqliteprojectioncolumns
sql
SELECT id, email, created_at FROM users;
Notes

Fetching only the columns you need reduces transfer and simplifies downstream code.

Filter with WHERE and LIKE

Find rows by pattern.

sqlANYsqlitewherelike
sql
SELECT id, title FROM posts WHERE title LIKE '%sqlite%';
Notes

LIKE is convenient for simple matching; full-text search is better for larger text search needs.

Sort and limit results

Get recent rows first.

sqlANYsqliteorder bylimit
sql
SELECT id, email, created_at FROM users ORDER BY created_at DESC LIMIT 20;
Notes

A core pattern for dashboards, logs, and feed-style pages.

Paginate with LIMIT and OFFSET

Fetch one page of rows.

sqlANYsqlitepaginationoffset
sql
SELECT id, email FROM users ORDER BY id LIMIT 20 OFFSET 40;
Notes

Works well for smaller datasets, though keyset pagination scales better for very large tables.

Insert, update, delete, and upsert

Core write patterns including conflict handling.

Insert one row

Add a new record.

sqlANYsqliteinsert
sql
INSERT INTO users (email, display_name) VALUES ('ava@example.com', 'Ava');
Notes

Explicit column lists make inserts safer as schemas evolve.

Insert multiple rows

Add several records in one statement.

sqlANYsqlitebulk insert
sql
INSERT INTO tags (name) VALUES ('sql'), ('sqlite'), ('database');
Notes

Batch inserts are concise and usually faster than one statement per row.

Update matching rows

Modify one or more records.

sqlANYsqliteupdate
sql
UPDATE users SET timezone = 'America/Los_Angeles' WHERE id = 1;
Notes

Always verify the WHERE clause when running updates interactively.

Delete matching rows

Remove records by condition.

sqlANYsqlitedelete
sql
DELETE FROM sessions WHERE expires_at < CURRENT_TIMESTAMP;
Notes

A common cleanup pattern for caches, sessions, and temporary records.

Upsert with ON CONFLICT

Insert or update on a uniqueness collision.

sqlANYsqliteupserton conflict
sql
INSERT INTO users (email, display_name)
VALUES ('ava@example.com', 'Ava Martin')
ON CONFLICT(email) DO UPDATE SET display_name = excluded.display_name;
Notes

A high-value pattern for sync jobs, imports, and idempotent writes.

Ignore duplicates on conflict

Keep the existing row when a unique key collides.

sqlANYsqlitedo nothingconflict
sql
INSERT INTO tags (name) VALUES ('sqlite') ON CONFLICT(name) DO NOTHING;
Notes

Useful for de-duplicated lookup tables and seeding scripts.

Recommended next

No recommendations yet.