View Single Post
Old 08-07-2011, 10:07 AM  
critical
Confirmed User
 
Join Date: Aug 2009
Posts: 478
If you are trying to obtain a range, just use mysql's range function:

May times the programmer needs to find out some specific data which lies in the particular range of values but there is not any predefined function in MySQL but we can also find that particular range's data from the database in MySQL using BETWEEN and AND clauses or write your own simple query.

Syntax:

exp BETWEEN min_value AND max_value
The above syntax is equivalent to the expression (min_value <= exp AND exp <= max_value).

In the following example we will describe you that how one can find out specific data lying between some range. To fire query we must have some data into a table therefore we will first create a table and fill some data into it.

Example:

SELECT id, name, subject from mca where
mca.id BETWEEN 2 AND 5;
Above query can also be written as below:

SELECT id, name, subject from mca where
( mca.id >=2 && mca.id <=5);
critical is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote