| | |
SQL BETWEEN Command to fetch records from a rangeMany times we may require to find out records between a range of value.
We can specify one upper limit and one lower limit and the query should return
all the records between these two values. The sql BETWEEN command will give us
the required result in all these cases. We will
apply here BETWEEN command to a numeric field and see how the records are
returned from a Mysql table. Here is our table.
| id
| name |
class |
mark |
| 1 |
John Deo |
Four |
75 |
| 2 |
Max Ruin |
Three |
85 |
| 3 |
Arnold |
Three |
55 |
| 4 |
Krish Star |
Four |
60 |
| 5 |
John Mike |
Four |
60 |
| 6 |
Alex John |
Four |
55 |
On this table we will apply our BETWEEN command to get all the records
within some upper and lower limits. Say our upper limit is 75 and lower limit is
60. So we will get all the records within these limits and please note that
limit 60 and 75 both are inclusive. Here is our sql BETWEEN command.
SELECT * FROM `student`WHERE mark BETWEEN 60 and 75
| id |
name |
class |
mark |
| 1 |
John Deo |
Four |
75 |
| 4 |
Krish Star |
Four |
60 |
| 5 |
John Mike |
Four |
60 |
You can see we have all the records between 60 and 75 ( both inclusive).
Please note that we have to first start with lower limit and then upper limit.
So the records between 60 and 75 will be displayed ( NOT BETWEEN 75 and 60 )
Selecting records between two date ranges
|
| | Sajib | 31-03-2010 |
|---|
| thanks. this is very helpful. | | alan | 08-11-2010 |
|---|
| so how would you have just the marks for id 4 and 5 display? | | Bas | 14-01-2011 |
|---|
| SELECT * FROM `student` WHERE id=4 and id=5 | | keerthana | 14-09-2011 |
|---|
| hi.. i need a mysql query for selecting transactions between two dates | | Sam in Kenya | 25-09-2011 |
|---|
Hie keerthana:
SELECT date from jobvacancies WHERE `date` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 12 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH)
| | mebrahtu | 28-11-2011 |
|---|
I have read (the SQL BETWEEN Command to fetch records from a range ) above.
And it was very informative and helpful.thanks for who posted it. | | rasheed | 12-01-2012 |
|---|
| i need a query of sql to get ten top student from table on base of their marks plz help any one | | Jone | 18-01-2012 |
|---|
@rasheed:
SELECT * FROM Students ORDER BY Marks DESC LIMIT 10 | | Azim | 20-02-2012 |
|---|
| how to use BETWEEN command using upper limit and lower limit exclusive | | reno rey quiza | 03-10-2012 |
|---|
| thanks a lot... this is really helpful... ! may you be returned a favor.. :)) | | naveen | 27-10-2012 |
|---|
| i want only 50% marks in sql query | | PRAMOD | 01-01-2013 |
|---|
TWO TABLES ARE GIVEN ,EMPLOYEES AND DEPARTMENT .
DISPLAY THE NAMES OF ALL THE EMPLOYEES WHOSE SALARY IS NOT WITHIN THE RANGE FOR THE CORRESPONDING DEPARTMENT | | mahamad | 26-03-2013 |
|---|
| i want to do pagination in jsp so how i will be able to do that?plz help me ... |
|
| |
|
|
|