The WHERE clause is used for filtering records in MySQL queries. It specifies conditions that records must meet to appear in the result. WHERE can be used with SELECT, UPDATE, DELETE and other SQL statements. Basic syntax:
SELECT column1, column2 FROM table_name WHERE condition;
In the WHERE clause, you can use the following operators:
| Operator | Description | Usage Example |
|---|---|---|
| = | Equal | WHERE name = "John" |
| > | Greater than | WHERE age > 30 |
| < | Less than | WHERE age < 25 |
| >= | Greater than or equal | WHERE age >= 18 |
| <= | Less than or equal | WHERE price <= 100 |
| <> or != | Not equal | WHERE country <> "Germany" |
| AND | Combines multiple conditions, all must be true | WHERE age > 20 AND country = "UK" |
| BETWEEN | Between a certain range | WHERE age BETWEEN 18 AND 30 |
| LIKE | Search for a pattern in text | WHERE name LIKE "J%" |
| IN | Specifies multiple possible values for a column | WHERE country IN ("UK", "USA") |
| NOT | Negation of other operators | WHERE NOT country = "Germany" |
| OR | Alternative conditions, at least one must be true | WHERE city = "London" OR city = "Paris" |
Conditions can include:
The WHERE clause is a powerful tool for:
Thank you for visiting! Adding privacy policy.
© 2024 All rights reserved.
Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.