[eluser]a&w[/eluser]
I was trying to leverage Active Record to do a join. Below I'm showing one that works and one that doesn't.
This version works.
Active record query generation:
Code:
$this->db->from('table_1');
$this->db->from('table_2');
$this->db->order_by('table_1.id', 'ASC');
$this->db->limit(25, 0);
$this->db->select('*');
$where = "`table_2`.`id` = `table_1`.`id`";
$this->db->where($where);
$query = $this->db->get();
generates this query:
Code:
SELECT *
FROM (`table_1`, `table_2`)
WHERE `table_2`.`id` = `table_1`.`id`
ORDER BY `table_1`.`id` ASC
LIMIT 25;
And I get results. Ok good. But I had to manually do the "WHERE" clause. So I tried to do generate the same query using a join:
Code:
$this->db->from('table_1');
$this->db->from('table_2');
$this->db->order_by('table_1.id', 'ASC');
$this->db->limit(25, 0);
$this->db->select('*');
$join = 'inner';
$this->db->join('table_2', 'table_2.id = table_1.id', $join);
//$where = "`table_2`.`id` = `table_1`.`id`";
$this->db->where($where);
$query = $this->db->get();
But that generates this query:
Code:
SELECT *
FROM (`table_1`, `table_2`)
INNER JOIN `table_2` ON `table_2`.`id` = `table_1`.`id`
ORDER BY `table_1`.`id` ASC
LIMIT 25;
Which has this result:
Code:
Error Code : 1066
Not unique table/alias: 'table_2'