SELECT * FROM users WHERE age >= 18;SELECT * FROM products WHERE price < 50.00;SELECT * FROM orders WHERE status == 'completed';SELECT * FROM inventory WHERE quantity != 0;
Databas uses == for equality comparison (not =). This follows the convention of many programming languages.
-- Multiplication before additionSELECT 2 + 3 * 4; -- Result: 14 (evaluated as 2 + (3 * 4))-- Comparison before ANDSELECT * FROM users WHERE age > 18 AND status == 'active';-- Evaluated as: (age > 18) AND (status == 'active')-- AND before ORSELECT * FROM users WHERE role == 'admin' OR role == 'mod' AND verified == true;-- Evaluated as: (role == 'admin') OR ((role == 'mod') AND (verified == true))
You can use parentheses to override the default precedence:
-- Force addition before multiplicationSELECT (2 + 3) * 4; -- Result: 20-- Force OR before ANDSELECT * FROM users WHERE (role == 'admin' OR role == 'mod') AND verified == true;-- Both admins and mods must be verified-- Complex nested expressionsSELECT * FROM products WHERE (price > 100 OR featured == true) AND in_stock == true;
-- Calculate total with taxSELECT price * 1.08 FROM products;-- Calculate discount priceSELECT price * (1 - discount / 100) FROM products;-- Find products within budgetSELECT * FROM products WHERE price * quantity <= 1000;
-- Premium users or trial users with verificationSELECT * FROM users WHERE premium == true OR (trial == true AND verified == true);-- Active users not in trialSELECT * FROM users WHERE active == true AND NOT trial;-- Complex eligibility checkSELECT * FROM users WHERE (age >= 18 AND verified == true) OR (age >= 13 AND parent_consent == true);