Home >Database >Mysql Tutorial >Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?

Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?

DDD
DDDOriginal
2024-10-30 16:34:03676browse

Why Does My MySQL Query Not Retrieve Records Older Than 15 Minutes?

Pulling Records Older Than a Specific Time Using MySQL

When attempting to select records with a datetime column falling within a specific time range, such as those older than 15 minutes, you may encounter unexpected results. The query provided in the question, which employs the >= operator, retrieves no records. To rectify this issue, you should use the < operator instead.

Modified Query:

<code class="mysql">WHERE creation_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)

Explanation:

The modified query correctly uses the < operator to specify that creation_date must be strictly less than the current time minus 15 minutes. This operation ensures that only records older than 15 minutes are retrieved.

Note:

When dealing with datetime comparisons, it's crucial to use the appropriate operator. The >= operator, commonly used to retrieve records that are greater than or equal to a specific time, does not suit the requirement in this query.

The above is the detailed content of Why Does My MySQL Query Not Retrieve 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