SQL BETWEEN Statement
$count++; if($count == 1) { include "../mobilemenu.php"; } if ($count == 2) { include "../sharemediasubfolder.php"; } ?>
SQL BETWEEN returns values between a given range.
SQL NOT BETWEEN returns values that are outside a given range.
Instead of BETWEEN you can use >= and <=, but it will make your query longer.
Let us look at examples to make this clear.
Imagine we have table called CUSTOMERS, with the following data:
FIRSTNAME
LASTNAME
AGE
COUNTRY
Rambo
Robert
25
Belgium
Mugambo
Satraj
37
Norway
Nagashekar
Rao
47
India
Tom
Harry
27
Brazil
Dana
Laura
21
Australia
Rambo
Fox
57
New Zealand
Giselle
Chivvi
87
Japan
SELECT * from Customer WHERE AGE BETWEEN (22, 50)
Result:
FIRSTNAME
LASTNAME
AGE
COUNTRY
Rambo
Robert
25
Belgium
Mugambo
Satraj
37
Norway
Nagashekar
Rao
47
India
Tom
Harry
27
Brazil
Scenario 2: Get me all records where Customer's Age is NOT between 22 and 50. We can use a NOT BETWEEN Clause to specify the above criteria.
SELECT * from Customer WHERE AGE NOT BETWEEN (22, 50)
Result:
FIRSTNAME
LASTNAME
AGE
COUNTRY
Dana
Laura
21
Australia
Rambo
Fox
57
New Zealand
Giselle
Chivvi
87
Japan