SQL Practice Logo

SQLPractice Online

Complex WHERE Conditions & Boolean Logic: Interview

Module: Advanced Filtering

What is the precedence order of AND, OR, NOT?

NOT has highest precedence, then AND, then OR (lowest). Use parentheses to override precedence and improve clarity.

Why are parentheses important in complex WHERE clauses?

Parentheses control evaluation order and make logic explicit. Without them, operator precedence can cause unexpected results, especially with mixed AND/OR conditions.

Find active or trial customers in US/CA with value >$1000

SELECT * FROM customers WHERE (status = 'active' OR status = 'trial') AND country IN ('US', 'CA') AND lifetime_value > 1000;

Parentheses group OR conditions, then AND filters by country and value. Clear, correct logic.