Search Marketing

   
   

Using Between in Select Query

Fri May 02, 2008 9:56 pm
<<     >>
Comments: 0 Views: 2612

The Between action in MySQL Select Statements can be used to select a range, either of Dates, Integers or Strings.

If we use the following database table information.

mysql> select * from Name;
+----+--------+---------------------+
| ID | Name | Date |
+----+--------+---------------------+
| 1 | Joe | 2001-02-12 00:00:00 |
| 2 | Jack | 2003-03-15 00:00:00 |
| 3 | John | 1980-05-15 00:00:00 |
| 4 | James | 1994-09-21 00:00:00 |
| 5 | George | 1996-12-11 00:00:00 |
| 6 | Paul | 2007-10-09 12:54:58 |
+----+--------+---------------------+

1.We want to select all information from the above table where a Date falls between 2000 and 2010, inclusive.

mysql> select * from Name where Date between '2000-00-00' AND '2010-00-00';
+----+------+---------------------+
| ID | Name | Date |
+----+------+---------------------+
| 1 | Joe | 2001-02-12 00:00:00 |
| 2 | Jack | 2003-03-15 00:00:00 |
| 6 | Paul | 2007-10-09 12:54:58 |
+----+------+---------------------+

2. We want to select all information that falls between ID 2 and 4, inclusive.

mysql> select * from Name where ID between '2' AND '4';
+----+-------+---------------------+
| ID | Name | Date |
+----+-------+---------------------+
| 2 | Jack | 2003-03-15 00:00:00 |
| 3 | John | 1980-05-15 00:00:00 |
| 4 | James | 1994-09-21 00:00:00 |
+----+-------+---------------------+


Comments
Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (21 + 4)
* required
SubCategories
Books

© 2017 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc