Friday, 5 October 2012

Simple WHERE Clause

The WHERE clause is used to filter records.

________________________________________

The WHERE Clause

The WHERE clause is used to extract only those records that fulfill a specified criterion.

SQL WHERE Syntax

SELECT column_name(s)

FROM table_name

WHERE column_name operator value

________________________________________

WHERE Clause Example

The "Persons" table:

P_Id    LastName    FirstName    Address    City
Hansen    Ola    Timoteivn 10 Sandnes
2    Svendson    Tove    Borgvn 23 Sandnes
3    Pettersen    Kari    Storgt 20  Stavanger

Now we want to select only the persons living in the city "Sandnes" from the table above.

We use the following SELECT statement:

SELECT * FROM Persons

WHERE City='Sandnes'

The result-set will look like this:

P_Id    LastName    FirstName    Address    City
Hansen    Ola    Timoteivn 10 Sandnes
2    Svendson    Tove    Borgvn 23 Sandnes
Buy These

No comments:

Post a Comment