Home > Database > Mysql Tutorial > body text

Why Does My Query Return Zero Results for Records Older Than 15 Minutes?

Mary-Kate Olsen
Release: 2024-10-27 09:17:02
Original
586 people have browsed it

Why Does My Query Return Zero Results for Records Older Than 15 Minutes?

WHERE datetime older than some time (eg. 15 minutes)

Question:

Why does the following query return 0 results for records older than 15 minutes, despite there being such records in the database?

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

Answer:

The query should be modified to use < (less than) instead of >= (greater than or equal to) to correctly select records older than 15 minutes:

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

Using >= would select records that are either equal to or greater than the current time minus 15 minutes, effectively excluding records older than 15 minutes.

The above is the detailed content of Why Does My Query Return Zero Results for 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
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!