Home > Database > Mysql Tutorial > How to query the latest record in mysql

How to query the latest record in mysql

WBOY
Release: 2022-01-20 11:31:41
Original
13349 people have browsed it

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;
Copy after login

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template