查詢MySQL數據庫,獲取最新的記錄


1、查詢單條最新的記錄

select * from table order by create_time limit 1;

2、查詢多條的最新記錄

  單表查詢:

select type, max(create_time) from table
group by type

  多表查詢:

select t1.*, t2.create_time, t2.type from (
select type, max(create_time)

from table
group by type) t1
left join table2 t2 on t1.id = t1.id

 

------ 新手隨筆,如有錯誤歡迎指出;有更好的方法也歡迎大家評論區留言,感謝大佬


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM