I need to write a join query of two tables from two databases and fetch the joined data. For eg, consider I have a database db1 which has some tables named companies, plans,
I'm having table x in DB1 which contain id, name and y_id. In DB2 there is a y table with id and name
so if you need to get name of x and y in a same query the here is your answer:
$db = $this->load->database("DB2", TRUE);
$DB = $this->load->database("DB1", TRUE);
$DB->select('x.name as name1, y.name as name2');
$DB->from('x');
$DB->join($db->database.'.y','x.y_id = y.id');
$res = $DB->get();