1

I have this working query:

$q = $this->db->query('SELECT u.name  FROM users u 
JOIN user_group ug ON u.id = ug.user_id 
JOIN groups g ON g.id = ug.group_id WHERE ug.group_id = "4" ');

And I want to replace it with aactive record. I come up with something like this but obviously it doesn't work :

$this->db->select('name');
   $this->db->from('users');
   $this->db->join('user_group', 'user_group.user_id = users.id);
   $this->db->join('groups', 'groups.id = user_group.group_id');
   $q = $this->db->get();

Thanks Leron

0

1 Answer 1

5

I think you forget add where clause. And there was single quote missing.

$this->db->select('name');
$this->db->from('users');
$this->db->join('user_group', 'user_group.user_id = users.id');
$this->db->join('groups', 'groups.id = user_group.group_id');
$this->db->where('user_group.group_id', 4);
$q = $this->db->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.