Reputation: 123
I am working in codeigniter. I want to know, how to write below code in codeigniter..
SELECT p.* FROM people p WHERE p.age = (select max(subp.age) from people subp);
Upvotes: 0
Views: 32
Reputation: 5398
There are many ways to do this such as
$sql = 'SELECT p.* FROM people p WHERE p.age = (select max(subp.age) from people subp)';
$query = $this->db->query($sql);
$result = $query->result_array();
Upvotes: 0
Reputation: 21437
This will work
$this->db->select('p.*');
$this->db->from('people p');
$this->db->where('p.age = (select max(subp.age) from people subp)',null,false);
$result = $this->db->get()->result_array();
print_r($result);
Upvotes: 1