|
Conditional Selection
To further discuss the SELECT statement, let's look at a new example table
(for hypothetical purposes only):
|
EmployeeStatisticsTable
|
|
EmployeeIDNo
|
Salary
|
Benefits
|
Position
|
|
010
|
75000
|
15000
|
Manager
|
|
105
|
65000
|
15000
|
Manager
|
|
152
|
60000
|
15000
|
Manager
|
|
215
|
60000
|
12500
|
Manager
|
|
244
|
50000
|
12000
|
Staff
|
|
300
|
45000
|
10000
|
Staff
|
|
335
|
40000
|
10000
|
Staff
|
|
400
|
32000
|
7500
|
Entry-Level
|
|
441
|
28000
|
7500
|
Entry-Level
|
Relational Operators
There are six Relational Operators in SQL, and after introducing them, we'll see
how they're used:
|
=
|
Equal
|
|
< or != (see manual)
|
Not Equal
|
|
<
|
Less Than
|
|
>
|
Greater Than
|
|
<=
|
Less Than or Equal To
|
|
>=
|
Greater Than or Equal To
|
The WHERE clause is used to specify that only certain rows of the
table are displayed, based on the criteria described in that WHERE clause.
It is most easily understood by looking at a couple of examples.
If you wanted to see the EMPLOYEEIDNO's of those making at or over $50,000,
use the following:
SELECT EMPLOYEEIDNO
FROM EMPLOYEESTATISTICSTABLE
WHERE SALARY >= 50000;
Notice that the >= (greater than or equal to) sign is used, as we wanted
to see those who made greater than $50,000, or equal to $50,000, listed
together. This displays:
EMPLOYEEIDNO
------------
010
105
152
215
244
The WHERE description, SALARY >= 50000, is known as a condition
(an operation which evaluates to True or False). The same can be done for
text columns:
SELECT EMPLOYEEIDNO
FROM EMPLOYEESTATISTICSTABLE
WHERE POSITION = 'Manager';
This displays the ID Numbers of all Managers. Generally, with text columns,
stick to equal to or not equal to, and make sure that any text that appears in
the statement is surrounded by single quotes ('). Note: Position
is now an illegal identifier because it is now an unused, but reserved, keyword
in the SQL-92 standard.
|