[英]How to get min and max value from the same column at same time from database in codeigniter?
[英]How to get max value and its row at the same time?
在“专辑头”表中,“专辑头_图片_id”是自动递增的主键。 我正在尝试获取“ album_head_picture_id”的最大值以及针对该ID的整行。 什么是SQL? 我试过了
<?PHP $maximim_id=$this->db->query('SELECT MAX(album_head_picture_id) AS 'maxid' FROM album_head')->row()->maxid;?>
并使用该ID,再次...
<?PHP $query = $this->db->query("
SELECT * FROM album_head where album_head_picture_id= '.$maximim_id.'");
return $query->result();
?>
我正在尝试在同一条sql中做到这一点。 任何想法? 提前致谢。
SELECT * FROM album_head where album_head_picture_id=(SELECT MAX(ID) FROM table)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.