MySQL WHERE clause
The WHERE
clause in MySQL is used to filter records in a query result set. It specifies a condition that must be satisfied in order for a row to be returned in the result set. The WHERE
clause is used in various SQL statements such as SELECT
, UPDATE
, and DELETE
.
Here’s a basic syntax of the WHERE
clause in a SELECT
statement:
The MYSQL where clause is the mechanism for selecting the row you want for your result set.
SELECT column1, column2, ...
FROM table_name
WHERE condition;
The condition
in the WHERE
clause is a logical expression that evaluates to either TRUE
or FALSE
. If the condition evaluates to TRUE
, the row is returned in the result set. If the condition evaluates to FALSE
, the row is not returned in the result set.
Here’s an example that uses the WHERE
clause to select all rows from the customers
table where the country
is ‘USA’:
SELECT *
FROM customers
WHERE country = 'USA';
In Select query expressions in WHERE clauses can use the following type of operation:
Arithmetic for calculation
Comparison for comparison of one expression with another expression.
Logical to combine different WHERE conditions.
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 |