Reputation: 1064
I want to Join the two tables in CodeIgniter in a single column. For example, There is table A as shown in images
Table B
Desired Result After Joining Table A and Table B
Upvotes: 1
Views: 159
Reputation: 2352
Try this
$result1 = $this->db->get('TableA');
$result2 = $this->db->get('TableB');
If you want to merge only specific columns use select()
$this->db->select('name');
$result1 = $this->db->get('TableA');
$this->db->select('name');
$result2 = $this->db->get('TableB');
And now merge these two records
$combine = array_merge($result1, $result2);
Read more about array_merge()
Upvotes: 1
Reputation: 2355
Try this,
$tableA = $this->db->select('name')->get_compiled_select('tableA');
echo $tableA;
$tableB = $this->db->select('name')->get_compiled_select('tableB');
echo $tableB;
$tableAB = $this->get_compiled_select($tableA.' UNION '.$tableB);
echo $tableAB;
$query = $this->db->query($tableAB);
Output:
SELECT name FROM tableA
SELECT name FROM tableB
SELECT name FROM tableA UNION SELECT name FROM tableB
OR:
$query = $this->db->query("SELECT name FROM tableA UNION SELECT name FROM tableB");
Upvotes: 1