tags:

views:

34

answers:

2

I have 03 tables with relationship

jos_session
 +userid

jos_gj_user
  +id_user
  +id_group

jos_gj_jb
  +group_id
  +category_id

I AM WANT TO COUNT user in table jos_session base on category_id in table jos_gj_jb

This is what I am trying

 SELECT COUNT(s.userid) 
 FROM jos_session s 
 WHERE s.user.id IN (SELECT id_user 
                     FROM jos_gj_user
                     WHERE id_group(SELECT group_id FROM jos_gj_jb WHERE category_id= .$variable.))

HOW CAN COUNT user_id for a category_id?

+1  A: 

While I am not absolutely sure if I understand your question, here is my suggestion:

SELECT COUNT( DINSTINCT id_user )
FROM jos_gj_user INNER JOIN jos_gj_jb ON id_group = group_id
WHERE category_id= $variable

This query will return the number of distinct users being member of one or my groups related to the category referenced by the value in $variable.

Jørn Schou-Rode
A: 
 SELECT COUNT( DINSTINCT id_user )
 FROM jos_session INNER JOIN jos_gj_user ON id_user = userid INNER JOIN jos_gj_group ON id_group = group_id
 WHERE category_id= $variable GROUP BY category_id
nanda
-1: Way to cut and paste the other guys typo too.
hobodave