Use the WHERE and QUALIFY clauses to return only the rows that match specific conditions in Snowflake.
Use WHERE in the SELECT statement to filter rows before aggregation or ordering. It improves query speed by discarding irrelevant data early.
Combine conditions with AND, OR, and parentheses for clear logic. AND narrows results; OR widens them. Parentheses ensure the intended precedence.
Window functions run after WHERE, so their results cannot be filtered with WHERE.QUALIFY lets you keep or drop rows based on window-function output.
Yes—use HAVING with GROUP BY. HAVING runs after grouping, allowing filters on COUNT, SUM, AVG, and more.
Filter on highly selective columns, use comparison operators that allow pruning, and avoid casting columns inside the WHERE clause to maintain partition pruning.
SELECT *
.
FROM Orders
WHERE order_date >= CURRENT_DATE - 30
AND total_amount > 500;
No. WHERE cannot reference column aliases defined in the same SELECT list. Use a subquery or repeat the expression.
Yes. Use the RLIKE operator: WHERE email RLIKE '.*@example\\.com$'.
Use IS NULL or IS NOT NULL, e.g., WHERE total_amount IS NOT NULL.