Operator quick reference
Equality (=)
- Use = to match exact values.
- Use >, <, >=, <= just like in most programming languages to compare numeric or date values.
- SQL supports two common not-equal syntaxes: <> (SQL standard) and != (supported by many engines such as PostgreSQL).
Use <> when you want to follow SQL standard syntax. Many databases accept both
<> and !=; pick one consistent with your team’s style guide or your DBMS documentation.- Use AND to require multiple conditions and OR to return rows that satisfy at least one condition.
- Use parentheses to control precedence when mixing AND and OR.
- Forgetting the WHERE keyword is a frequent source of syntax errors.
Always include WHERE after FROM (and after any JOIN clauses) when filtering rows. When queries become complex, format and indent conditions to make missing keywords obvious.
- Use =, >, <, >=, <= for comparisons.
- Prefer <> for not-equal to follow SQL standard;
!=is often supported but be consistent. - Combine conditions with AND and OR; use parentheses to group logic explicitly.
- Place WHERE after FROM (and after JOINs) — omitting it causes syntax errors.
- For readability and maintainability, format multi-condition WHERE clauses on multiple lines and consider adding comments for complex boolean logic.