简体   繁体   中英

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. I am trying to get the max of 'album_head_picture_id' and the entire row against that id. What is the 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...

<?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. Any Idea? thanks in advance.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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