How to get maximum value in MySQL table column using Codeigniter

To find max value form query select_max method in codeigniter

CodeIgniter is a framework based on MVC principles. As a result, you would usually separate application logic, data abstraction and “output” into their respective areas for CodeIgniter use. In this case: controllers, models and views.

Codeigniter provides select_max method to get maximum value in mysql table column. Writes a SELECT MAX(field) portion for your query. You can optionally include a second parameter to rename the resulting field.

Let’s create a select_max method in codeigniter

$this->db->select_max('amount');
$result = $this->db->get('tbl_product')->row();
return $result->amount;

Leave a Reply

Your email address will not be published. Required fields are marked *