| name | price | id | is_sale | inventory | created_at |
|---|---|---|---|---|---|
| TV | 200 | 1 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| DVD Players | 80 | 2 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| remote | 10 | 3 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| microphone | 30 | 5 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| Car | 40 | 7 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| pencil | 2 | 8 | false | 0 | 2021-08-20 00:49:58.021274-04 |
| pencil sharpener | 4 | 9 | true | 0 | 2021-08-20 00:49:58.021274-04 |
| keyboard | 28 | 10 | false | 50 | 2021-08-20 00:50:48.457985-04 |
| soda | 2 | 11 | true | 10 | 2021-08-20 23:01:37.283024-04 |
| pizza | 13 | 12 | true | 22 | 2021-08-20 23:01:37.283024-04 |
| toothbrush | 2 | 13 | true | 8 | 2021-08-20 23:01:37.283024-04 |
| toilet paper | 4 | 14 | false | 100 | 2021-08-20 23:02:37.786025-04 |
| xbox | 380 | 15 | true | 45 | 2021-08-20 23:04:23.608326-04 |
| Operator | Meaning | Example |
|---|---|---|
| = | Equal to | WHERE price = 200 |
| <> | Not equal (SQL standard) | WHERE inventory <> 0 |
| != | Not equal (also supported) | WHERE inventory != 0 |
| > | Greater than | WHERE price > 50 |
| >= | Greater than or equal to | WHERE price >= 80 |
| < | Less than | WHERE price < 80 |
| <= | Less than or equal to | WHERE price <= 80 |
| AND | Logical AND (both conditions true) | WHERE inventory > 0 AND price > 20 |
| OR | Logical OR (either condition true) | WHERE price > 100 OR price < 20 |
- 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.