Sometimes you will not want all the rows in a table. Let's say that we only want people whose surname is "Rubble" In order to do this in SQL you must add a WHERE clause.

SELECT *

FROM PERSONAL

WHERE surname="Rubble"

The WHERE clause allows us to restrict the results. If the above command was executed then the results would be -

ID

Surname

Forename

Age

2

Rubble

Barney

42

5

Rubble

Betty

40

All the basic comparison operators can be used. For example

SELECT forename, age

FROM PERSONAL

WHERE age >=40

Which produces the results -

Forename

Age

Barney

42

Flintstone

65

Betty

40

The operators which you can use are

Operator

Meaning

=

Equal

<>  

Not equal

>  

Greater than

<  

Less than

>= or <=

Greater/less than or equals