MySQL WHERE clause
The MYSQL where clause is the mechanism for selecting the row you want for your result set.
SYNTAX
SELECT DISTINCT
columns
FROM
table_name
WHERE where_conditions;
Example for MySQL WHERE clause
SELECT code,name from Country where continent=”asia”
Output for MySQL WHERE clause
mysql> SELECT code,name from Country where continent=”asia”;
+——+———————-+
| code | name |
+——+———————-+
| AFG | Afghanistan |
| ARE | United Arab Emirates |
| ARM | Armenia |
| AZE | Azerbaijan |
| BHR | Bahrain |
| BGD | Bangladesh |
| BTN | Bhutan |
| BRN | Brunei |
| PHL | Philippines |
| GEO | Georgia |
| HKG | Hong Kong |
| IDN | Indonesia |
| IND | India |
expressions in WHERE clauses can use the following type of operation:
Arithmetic for calculation
Camparison for comparison of one expression with another expression.
Logical to combine different WHERE condition.
Parameter For MySQL WHERE clause
Arithmetic Operation used in Mysql Where Clause
Operation | Definition |
---|---|
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
div | Interger Division |
% | Modulo |
Comparison Operator for MYSQL where Clause
Operation | Defination |
---|---|
< | Less then |
>= | Less then or equal to |
= | Equal to |
<=> | Equal (work even for NULL values) |
<> or != | Not equal to |
>= | Greater than or equal to |
> | Greater than or equal to |
Between … and. . | Indicate a range of values |
Logical Operator For where Clause
Operation | Definition |
---|---|
AND | Logical AND |
OR | Logical OR |
XOR | Logical exclusive OR |
NOT | Logical negation |