Home > Database > Mysql Tutorial > body text

Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?

DDD
Release: 2024-10-30 16:34:03
Original
579 people have browsed it

Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?

Pulling Records Older Than a Specific Time Using MySQL

When attempting to select records with a datetime column falling within a specific time range, such as those older than 15 minutes, you may encounter unexpected results. The query provided in the question, which employs the >= operator, retrieves no records. To rectify this issue, you should use the < operator instead.

Modified Query:

<code class="mysql">WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)
Copy after login

Explanation:

The modified query correctly uses the < operator to specify that creation_date must be strictly less than the current time minus 15 minutes. This operation ensures that only records older than 15 minutes are retrieved.

Note:

When dealing with datetime comparisons, it's crucial to use the appropriate operator. The >= operator, commonly used to retrieve records that are greater than or equal to a specific time, does not suit the requirement in this query.

The above is the detailed content of Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!