Using WHERE in Your Queries

You have learned numerous ways to retrieve particular columns from your tables, but not specific rows. This is when the WHERE clause comes in to play. From the example SELECT syntax, you see that WHERE is used to specify a particular condition:

SELECT expressions_and_columns FROM table_name
[WHERE some_condition_is_true]

An example would be to retrieve all the records for items with a quantity of 500:

						mysql> select * from grocery_inventory where curr_qty = 500; +----+-------------------+------------------------+------------+----------+ | id | item_name | item_desc | item_price | curr_qty | +----+-------------------+------------------------+------------+----------+ | 2 | Bunches of Grapes | Seedless grapes. | 2.99 ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.