Applying a condition

Rather than selecting all the records from the Employee table, you can select exactly which records you’d like to work with by applying a condition. To do this, you use the WHERE command.

For example, to work with only those employees who are in the sales department:

SELECT Department, FirstName, LastName FROM Employee WHERE Department = "SALES";

The results table would look like this:

Department

FirstName

LastName

SALES

Andreas

Smith

SALES

Julia

Allan

Here’s another example:

SELECT FirstName, LastName FROM Employee WHERE Age >= 30 ORDER BY LastName;

This returns a sorted list of employees over the age of 29.

The part of the SQL statement following the WHERE key word and preceding the ORDER BY keywords is called a condition and the ‘>=’ is called the operator. Here’s a list of all the operators you can use with Ability:

Operator

Meaning

=

Exactly Equal

!=

Not Equal

<

Less Than

>

Greater Than

<=

Less Than or Equal To

>=

Greater Than or Equal To

LIKE

Partial match

IS NULL

Contains no data

AND

Must match both conditions

OR

Match either condition

NOT

Reverses logic

IN

Matches one of a list

BETWEEN

Lies in-between two values

By using the operators together you can always define a condition to return the records you want.

See also:

Next topic - Numeric comparisons

Selecting records - the basics

Other types of SQL statements