Home  >  Article  >  Database  >  How to query the latest record in mysql

How to query the latest record in mysql

WBOY
WBOYOriginal
2022-01-20 11:31:4113248browse

In mysql, you can use the select query statement with the "order by" and limit clauses to query the latest record. The syntax is "select * from table name order by time field desc limit 0,1;".

How to query the latest record in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How does mysql query the latest record

Use order by time desc to query data in descending order of time and add limit limit 0,1 conditions from Start selecting a piece of data from the first piece of data, which is the latest record in the mysql database; the complete statement is as follows:

select * from table name order by time field desc limit 0,1;

Examples are as follows :

MYSQL queries the latest record of different users

How to query the latest record in mysql

After querying the results, sort the time and take the first one (only one can be obtained , and cannot query the records of different customers)

SELECT CUSTOMER_ID,CONTENT,MODIFY_TIME FROM `service_records` ORDER BY MODIFY_TIME DESC LIMIT 1;

Query results:

How to query the latest record in mysql

Recommended learning:mysql video tutorial

The above is the detailed content of How to query the latest record in mysql. 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