Go to: Articles List

SQL Basics Part 2 : Select with the Where Clause

Using the where clause adds power to the select statement. It allows you to narrow the amount of records that are returned back to you. For example, if you have a table that contains customer data and you want to get information for a specific customer out of it. You might issue a select statement like this:

SELECT * FROM CustomerData WHERE lname = 'Smith'

This would return to you all the columns from the CustomerData table and all of the records that had a last name equal to 'Smith'. What if you wanted all of the records that the last name started with 'S':

SELECT * FROM CustomerData WHERE lname LIKE 'S%'

The difference here is the addition of the keyword LIKE and the % sign. The % sign is a wildcard and the LIKE keyword does just what is says, shows you records like what you specify.