It is possible to provide more than one WHERE clause in order to restrict the results. Consider the query which finds all people who are older than 20 but less than 45. If we look at the query closer we can see there are two conditions.

  1. Age > 20
  2. Age < 45

We only want rows if they full fill both conditions. So rows only get returned if age > 20 AND age < 45. In order to say we want both conditions fulfilled we must use the logical connective AND. A logical connective is simply something which connects two conditions together using basic logic. AND is used in logic all of the time. If you have two statements A and B in order for A AND B to be true both A and B must be true. Bringing this all together we get -

SELECT *

FROM PERSONAL

WHERE age > 20 AND age < 45

ID

Surname

Forename

Age

1

Hamflett

A

25

2

Rubble

Barney

42

5

Rubble

Betty

40

There are two other logical connectives which are commonly used, OR and NOT.

OR basically says that only one of the conditions must be true. For example

SELECT *

FROM PERSONAL

WHERE surname="Rubble"OR surname="Flintstone"

Which produces the results -

ID

Surname

Forename

Age

2

Rubble

Barney

42