Index fields that are commonly used together.

Section: Create index patterns

Create a composite index

sql
sql
CREATE INDEX idx_orders_status_created_at ON orders (status, created_at DESC);
Explanation

Useful for queries that filter by `status` and then sort or range on `created_at`.

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 index patterns
Create a single-column index
Index a common lookup column.
OpenIn sheetsqlsame section
PostgreSQL covering index with INCLUDE
Store extra columns for index-only scans.
OpenIn sheetsqlsame section
Design for equality then range
Put equality columns first in many B-tree cases.
OpenIn sheetsqlsame section
Support ORDER BY with an index
Avoid expensive sorts when possible.
OpenIn sheetsql1 tag match
Example covering query
Query only indexed columns when possible.