Home > Database > Mysql Tutorial > body text

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

DDD
Release: 2024-10-26 16:05:02
Original
386 people have browsed it

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)
Copy after login

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)
Copy after login

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!

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!