Home  >  Article  >  Database  >  Why Does My Query Return Zero Results for Records Older Than 15 Minutes?

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

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-27 09:17:02587browse

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>

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)

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!

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