Welcome Guest, Not a member yet? Register   Sign In
Count items in category A & B (SQL question)
#1

[eluser]Unknown[/eluser]
I'm trying to alter an ExpressionEngine plugin to make it work for me. I think my question is pretty easy to anwer for someone who knows SQL. I have the following table:

entry_id | cat_id
5 | 3
6 | 3
7 | 3
7 | 5
8 | 5
9 | 3
9 | 5

Now I want to count all entry_ids that are in cat_id 3 and 5 (where both categories are selected). I'm using this:

Code:
$this->EE->db->select('exp_category_posts.entry_id');
$this->EE->db->join('exp_channel_titles', 'exp_category_posts.entry_id = exp_channel_titles.entry_id' );
$this->EE->db->where_in('cat_id', $cat_id);
Where $cat_id is an array of 3 & 5.

What could I do to get 2 as a result (entries 7 and 9 makes a sum of 2).

Hope someone can help. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB