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;".
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
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:
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!