Harris Khan
Harris Khan

Reputation: 247

how to get max and min value of a column from database in codeigniter

I want to get Min and Max value of Column using one query. Is that Possible?

Here is my code:

$this->db->select_max('fare');
$this->db->select_min('fare');
$this->db->from('travels_detail');
$query = $this->db->get();

Upvotes: 0

Views: 6278

Answers (1)

Rahul Patel
Rahul Patel

Reputation: 639

You can try this:

$this->db->select('MAX(fare) as max_fare, MIN(fare) as min_fare');
$this->db->from('travels_detail');
$query = $this->db->get();

Upvotes: 4

Related Questions