Worked SQL examples
Follow a SQL decision from source rows to returned results. Each worked example includes the exact query and a place to explore it in SQLite. For broader explanations of plans and indexes, read the SQL guides.
SQL composite index column order: filter before sort
Compare two composite index orders in SQLite. Keep the returned rows unchanged while moving from an index scan to a customer-specific search.
SQL WHERE vs HAVING: filter rows or groups
WHERE filters individual rows before grouping. HAVING filters groups after totals or other aggregate values are calculated. Compare both with a sales example.
LEFT JOIN with WHERE: why rows disappear
A WHERE condition on orders can remove customers with no matching paid order. Put the condition in ON to keep every customer and show NULL for missing matches.