MorkaLork Development

Interesting stuff I've picked up over the years...

Mysql 7.3: WHERE ... BETWEEN

2009-04-16 21:16:17 | 602 views | sql mysql table where between search

WHERE ... BETWEEN:



Sometimes you want search data that has a certain low and high limit. Such as searching a schedule between the hours 8.00 and 11.00 or your employee database for people between 20 and 30. This can be done using the BETWEEN keyword:


This will be our table 'person'

|--------------------+--------------------+--------------------|
|Name |Age |Gender |
|____________________+____________________+____________________|
|Bob 34 Male |
|Silvia 67 Female |
|Magnus 24 Male |
|Lisa 32 Female |
+--------------------------------------------------------------+


Syntax:


SELECT column
FROM table_name
WHERE column
BETWEEN condition1 AND condition2


Example:


SELECT *
FROM person
WHERE Age
BETWEEN 20 AND 40


|--------------------+--------------------+--------------------|
|Name |Age |Gender |
|____________________+____________________+____________________|
|Bob 34 Male |
|Magnus 24 Male |
|Lisa 32 Female |
+--------------------------------------------------------------+



Article comments

Feel free to comment this article using a facebook profile.

I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.