Home > Database > Mysql Tutorial > body text

Why Am I Not Getting Results When Selecting Records Older Than 15 Minutes in MySQL?

Linda Hamilton
Release: 2024-10-25 17:19:02
Original
213 people have browsed it

Why Am I Not Getting Results When Selecting Records Older Than 15 Minutes in MySQL?

Finding DateTime Records Older Than a Specific Time

In MySQL, selecting rows where a datetime column falls within a specified time range is a common task. However, when attempting to retrieve records older than a certain time interval, some users may encounter issues.

One such issue is described in a recent query, where a user attempted to pull records from a "creation_date" column that were older than 15 minutes using the query:

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

Surprisingly, the query returned no results, despite the presence of records that met the specified time frame. Upon closer examination, it was identified that the condition used (">=") was incorrect. To retrieve records older than 15 minutes, the correct condition should be:

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

The "<" operator ensures that the "creation_date" value falls before the specified time range, allowing the retrieval of the desired records. With this adjustment, the query should now accurately return all records that are older than 15 minutes in the "creation_date" column.

The above is the detailed content of Why Am I Not Getting Results When Selecting Records Older Than 15 Minutes in MySQL?. 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
Latest Articles by Author
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!