ImBhavin95
ImBhavin95

Reputation: 1527

Join Query issue - codeigniter

I have 2 tables tb_user_group and tb_user_follow_group i want to join this table in my style

tb_user_group

enter image description here

tb_user_follow_group

Group Follow Image

i want all records from tb_user_follow_group where tb_user_follow_group.group_id match with tb_user_group.id and is_follow='accept' also include tb_user_group.id = 1 and get all the fields of this two table.

not necessary answer in CodeIgniter Syntax post simple query also

This is my try query

$this->db->select('tb_user_follow_group.*,tb_user_group.*');
$this->db->from('tb_user_group');
$this->db->join('tb_user_follow_group', 'tb_user_group.id = tb_user_follow_group.group_id', 'left inner'); 
$query = $this->db->get();
return $query->result();

Upvotes: 0

Views: 74

Answers (1)

Shafiqul Islam
Shafiqul Islam

Reputation: 5690

try this but not tested

  select ug.* from tb_user_group ug LEFT JOIN tb_user_follow_group ufg ON ug.id = ufg.group_id WHERE ufg.is_follow='accept' OR ug.user_id='".$user_id."' GROUP BY ug.id;

Upvotes: 1

Related Questions