Welcome Guest, Not a member yet? Register   Sign In
Join Question
#1

[eluser]derekmichaeljohnson[/eluser]
I have 3 tables: users, users2cats, and cats. I'd like to be able to list all the categories, as well as the number of users in each. Can I do this with a single query?

My code so far:

Code:
$this->db->select('users.*, users2cats.cat_id, cats.name AS cat');
$this->db->from('users');
$this->db->join('users2cats', 'users.id = users2cats.user_id');
$this->db->join('cats', 'users2cats.cat_id = cats.id');


Messages In This Thread
Join Question - by El Forum - 07-05-2009, 05:19 PM
Join Question - by El Forum - 07-05-2009, 06:21 PM
Join Question - by El Forum - 07-05-2009, 06:31 PM
Join Question - by El Forum - 07-05-2009, 08:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB