Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter Active Record HAVING / WHERE db.field = db.field

Can someone tell me, if this is possible with active record - and how??

$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2', 'table1.id = table2.fi_id', 'left');
$this->db->having('table1.second_id','table2.fi_second_id', false);
$query = $this->db->get();

The problem ist, that 'table2.fi_second_id' is always treated as a string - not as a database field. Tried this with 'where' also - it's the same problem.

Thx

like image 522
Petra Avatar asked Mar 12 '13 11:03

Petra


1 Answers

I think that you want the following:

$this->db->having('table1.second_id = table2.fi_second_id',false);

You may or may not apply the false parameter if you don't need escaped SQL queries.

like image 197
Marc Audet Avatar answered Oct 04 '22 23:10

Marc Audet