https://www.brainbell.com/tutorials/MySQL/Combining_WHERE_Clauses.htm
AND
keyword used in a WHERE
clause to specify that only rows matching all the specified conditions should be retrieved.
To filter by more than one column, you use the AND
operator to append conditions to your WHERE
clause. The following code demonstrates this:
SELECT prod_id, prod_name, prod_price FROM products WHERE prod_id <= 5 AND prod_price <= 10;
+---------+------------+------------+
| prod_id | prod_name | prod_price |
+---------+------------+------------+
| 1 | product 1 | 5.99 |
| 2 | product 2 | 3.99 |
| 3 | product 3 | 8.99 |
| 5 | product 5 | 9.09 |
+---------+------------+------------+
+---------+------------+------------+ | prod_id | prod_name | prod_price | +---------+------------+------------+ | 1 | product 1 | 5.99 | | 2 | product 2 | 3.99 | | 3 | product 3 | 8.99 | | 5 | product 5 | 9.09 | +---------+------------+------------+
OR
Operator
OR
keyword used in a WHERE
clause to specify that any rows matching either of the specified conditions should be retrieved.
The OR
operator is exactly the opposite of AND
. The OR
operator instructs MySQL to retrieve rows that match either condition.
Look at the following SELECT
statement:
SELECT prod_name, prod_price FROM products WHERE prod_id <= 5 OR prod_price <= 10;
| prod_id | prod_name | prod_price | +---------+------------+------------+ | 1 | product 1 | 5.99 | | 2 | product 2 | 3.99 | | 3 | product 3 | 8.99 | | 4 | product 4 | 13.99 | | 5 | product 5 | 9.09 | | 6 | product 6 | 8.99 | | 7 | product 7 | 7.00 | | 8 | product 8 | 1.80 | | 10 | product 10 | 4.75 |
No comments:
Post a Comment