|
|
Some examples of simple WHERE
statements:
1 | The population of 'France' .Strings should be in 'single quotes'; |
---|
2 | The names and population densities for the very large
countries. We can use mathematical and string expressions as well as field names and constants. |
---|
3 | Where to find some very small, very rich countries. We use AND to ensure that two or more conditions hold
true.
|
---|
4 | Which of Ceylon , Iran ,
Persia and Sri Lanka is the
name of a country?The word IN allows us to check if an item is in a list.
|
---|
5 | What are the countries beginning with D? The word LIKE permits pattern matching - % is the
wildcard.
|
---|
6 | Which countries are not too small and not too big?BETWEEN allows range checking - note that it is
inclusive.
|
---|
SELECT
and
WHERE
These statements take the form :
SELECT attribute-list FROM table-name WHERE condition
attribute-list
+, -, *, /
may be used on
numeric values. String values may be concatenated using
||
name
, region
, area
,
population
and gdp
table-name
cia
.condition
AND
,
OR
, NOT
, >,
>=, =, <, <=LIKE
operator permits strings to be compared using
'wild cards'. The symbols _ and % are used to represent a
single character or a sequence of characters. Note that MS
Access SQL
uses ?
and *
instead of _
and %
.IN
operator allows an item to be tested against a
list of values.BETWEEN
operator for checking ranges.Boolean expressions often read like "normal" English however
the syntax is not as rich. For example we might say
name equals 'France' or 'Germany'
however the corresponding boolean expression is
name='France' OR name='Germany'