如何使用SQL语法从MySQL表中select最后一条logging

我有一个表有几个logging。 有一个ID字段。 我想select最近的id(即最高的id)的logging。

有任何想法吗?

SELECT * FROM table_name ORDER BY id DESC LIMIT 1 

用户按desc顺序sorting:

 select * from t order by id desc limit 1 

你也可以做这样的事情:

 SELECT tb1.* FROM Table tb1 WHERE id = (SELECT MAX(tb2.id) FROM Table tb2); 

当你想进行一些连接时,它很有用。

 SELECT * FROM table ORDER BY id DESC LIMIT 0, 1 
 SELECT MAX("field name") AS ("primary key") FROM ("table name") 

例:

 SELECT MAX(brand) AS brandid FROM brand_tbl 

我用了以下两个:

 1 - select id from table_name where id = (select MAX(id) from table_name) 2 - select id from table_name order by id desc limit 0, 1