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




 
Bookmark this page:
   
Rate this page:
  • Currently 2.86/5
  • 1
  • 2
  • 3
  • 4
  • 5

Rating: 2.9/5 (171 votes)



Comments:

please post comments
admin November 21, 2006

 
Nickname:
Comment:
Security: 1+1=
Hosts
Lunarpages.com Web Hosting
iPowerWeb

Domain Registrars
PPC Networks
Logos
Affiliate Networks
Resources