Home  >  Article  >  Database  >  Why Am I Not Finding Records Older Than 15 Minutes with My SQL Query?

Why Am I Not Finding Records Older Than 15 Minutes with My SQL Query?

DDD
DDDOriginal
2024-10-26 16:05:02388browse

Why Am I Not Finding Records Older Than 15 Minutes with My SQL Query?

Selecting Records with Timestamps Older Than a Specified Time

In the realm of database querying, determining the age of timestamps can be crucial. A recent query sought to find all records with timestamps older than 15 minutes, using the query:

WHERE creation_date >= DATE_SUB(NOW(), INTERVAL 15 MINUTE)

However, despite having records older than 15 minutes in the database, the query consistently returned no results. This prompted further investigation into the correct syntax.

The issue stemmed from the comparison operator used. The original query used "=>", which checks for timestamps greater than or equal to the specified interval. However, selecting records older than a specified time requires the use of "<", as in:

WHERE creation_date < DATE_SUB(NOW(), INTERVAL 15 MINUTE)

By using this modified syntax, the query will correctly identify timestamps that are older than the specified time interval, ensuring accurate retrieval of the desired data.

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

Statement:
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