SELECT Statement: the WHERE clause
Selecting specific rows is possible by using the WHERE clause of the SQL SELECT command. In its simplest form the syntax is:
SELECT column, column, ....
WHERE column = <column value>;
SELECT employee_number, forename, surname, salary
WHERE surname = 'Smith';
This will return the salary details of all employees whose surname is 'Smith'. You can see that this option has been combined with the previous example to return only specific columns. Note that this selection is case sensitive. If the surname had been stored as SMITH then WHERE surname = 'Smith' would not find this row.
This command works by comparing the data content of the surname column for each row in the table. If the condition is met then a 'true' value results, if not the result is 'false'. Those rows having a 'true' value are returned by the command.
The selection in the WHERE clause is not limited to the = operator. It can be any of the following operators:
|>=||Greater than or equal to|
|<=||Less than or equal to|
|<> or !-||Not equal to|
Several WHERE conditions can be combined by use of the logical operators "AND" or "OR". The logical operator NOT inverts a result. These are illustrated by the following examples: