Index multiple columns in query order.

Section: Create and use indexes

Create a composite index

sql
sql
CREATE INDEX idx_posts_user_created_at ON posts(user_id, created_at DESC);
Explanation

Composite indexes work best when they match common WHERE and ORDER BY patterns.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Create and use indexes
Create a basic index
Index a frequently filtered column.
OpenIn sheetsqlsame section
Create a unique index
Enforce uniqueness and speed up lookups.
OpenIn sheetsqlsame section
Create a partial index
Index only rows that match a predicate.
OpenIn sheetsqlsame section
Explain a query plan
See whether SQLite scans or uses an index.
OpenIn sheetsql1 tag match
Collect statistics with ANALYZE
Help the planner choose better indexes.
OpenIn sheetsql1 tag match
Rebuild indexes
Recreate indexes when needed.
OpenIn sheetsql1 tag match