Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL "between" clause not inclusive?

Tags:

sql

mysql

between

People also ask

Is between in MySQL inclusive?

The MySQL BETWEEN operator is inclusive. For example, when you use the MySQL BETWEEN operator to retrieve the books whose price is in the range between 50 and 90, the result retrieves all of these books, including those whose price equals 50 or 90.

Is SQL Between statement inclusive?

The SQL BETWEEN Operator The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.

Does between in MySQL include endpoints?

MySQL's BETWEEN includes all results between two endpoints as well as the endpoints.

What does <> mean in MySQL?

MySQLi MySQLDatabase. The symbol <> in MySQL is same as not equal to operator (!=). Both gives the result in boolean or tinyint(1). If the condition becomes true, then the result will be 1 otherwise 0.


From the MySQL-manual:

This is equivalent to the expression (min <= expr AND expr <= max)


The field dob probably has a time component.

To truncate it out:

select * from person 
where CAST(dob AS DATE) between '2011-01-01' and '2011-01-31'

The problem is that 2011-01-31 really is 2011-01-31 00:00:00. That is the beginning of the day. Everything during the day is not included.


select * from person where dob between '2011-01-01 00:00:00' and '2011-01-31 23:59:59'