MySQL - WHERE
Instructions on how to use the mySQL WHERE command to specify variables for you queries.
Using the SELECT statement by itself will rarely be of much use. Adding the WHERE clause will allow you to run a query and select data according to certain conditions.
SELECT columns FROM tablename WHERE columnname = 'value'
To select all columns you use a star where the column names go:
SELECT * FROM tablename WHERE column = 'value'
The following examples will use the following database.
WHERE clause - Select all columns
MySQL Code
|
|
$query="SELECT * FROM users WHERE firstname = 'John'";
| |
|
Results
|
|
| John |
Smith |
17 |
Ohio |
| John |
Kennedy |
35 |
Massachusetts |
|
|
|
WHERE clause - Select certain columns
MySQL Code
|
|
$query="SELECT firstname, lastname, state FROM users WHERE firstname = 'John'";
| |
|
Results
|
|
| John |
Smith |
Ohio |
| John |
Kennedy |
Massachusetts |
|
|
|
Comments:
 |
please post comments
|
 |
admin November 21, 2006
|
|