SureshK
SureshK

Reputation: 123

Convert query to codeigniter

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

Answers (2)

Rejoanul Alam
Rejoanul Alam

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

Narendrasingh Sisodia
Narendrasingh Sisodia

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

Related Questions