简体   繁体   English

如何同时获取最大值及其行?

[英]How to get max value and its row at the same time?

In 'album_head' table 'album_head_picture_id' is auto incremented primary key. 在“专辑头”表中,“专辑头_图片_id”是自动递增的主键。 I am trying to get the max of 'album_head_picture_id' and the entire row against that id. 我正在尝试获取“ album_head_picture_id”的最大值以及针对该ID的整行。 What is the sql? 什么是SQL? I tried this... 我试过了

<?PHP  $maximim_id=$this->db->query('SELECT MAX(album_head_picture_id) AS 'maxid' FROM album_head')->row()->maxid;?>

and with that id, again... 并使用该ID,再次...

<?PHP  $query = $this->db->query("
       SELECT * FROM album_head where album_head_picture_id= '.$maximim_id.'");

       return $query->result();
?>

i am trying to do that in same sql. 我正在尝试在同一条sql中做到这一点。 Any Idea? 任何想法? thanks in advance. 提前致谢。

SELECT * FROM album_head where album_head_picture_id=(SELECT MAX(ID) FROM table)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM