Not a Duplicate Question!!!
I am using CodeIgniter 3 - Query Builder Class with MySQLi.
$query = $this->db
->select('category_level_1.id, category_level_1.category')
->from('category_level_1')
->join('category_level_2', 'category_level_2.cat_lvl1_id != category_level_1.id', 'inner')
->group_by('category_level_1.id')
->get();
Only need to output records in 'category_level_1' Table which are not related with 'category_level_2' Table.
As showed above, output values are not as expected according to '!=' operator is not working with 'inner' join.
I suggest you try using a left
orright
join
and a where
clause. Give the following a go:
$query = $this->db
->select('category_level_1.id, category_level_1.category')
->from('category_level_1')
->join('category_level_2', 'category_level_2.cat_lvl1_id = category_level_1.id', 'left')
->where('category_level_2.cat_lvl1_id IS NULL')
->group_by('category_level_1.id')
->get();