Welcome Guest, Not a member yet? Register   Sign In
Active records - "smart" select
#2

[eluser]vitoco[/eluser]
I don't use active records, so i can only help you with plain sql :

Code:
$user_id = 1 ;
$sql = "
SELECT
  c.id AS community__id ,
  c.name AS community__name ,
  COUNT( DISTINT( c.user_id ) AS num_users_per_community
FROM
  communities AS c
LEFT JOIN
  user_communities AS uc
ON
  (
   uc.community_id = c.id AND
   (
    user_id <> ".$user_id." OR
    user_id IS NULL
   )
  )
GROUP BY
  c.id
ORDER BY
  num_users_per_community DESC
LIMIT
  0 , 2
";

Saludos


Messages In This Thread
Active records - "smart" select - by El Forum - 06-15-2012, 12:22 PM
Active records - "smart" select - by El Forum - 06-15-2012, 09:41 PM
Active records - "smart" select - by El Forum - 06-15-2012, 09:47 PM
Active records - "smart" select - by El Forum - 06-15-2012, 09:59 PM
Active records - "smart" select - by El Forum - 06-15-2012, 09:59 PM
Active records - "smart" select - by El Forum - 06-15-2012, 10:00 PM
Active records - "smart" select - by El Forum - 06-15-2012, 10:21 PM
Active records - "smart" select - by El Forum - 06-15-2012, 10:51 PM
Active records - "smart" select - by El Forum - 06-15-2012, 10:57 PM
Active records - "smart" select - by El Forum - 06-15-2012, 10:59 PM
Active records - "smart" select - by El Forum - 06-15-2012, 11:07 PM
Active records - "smart" select - by El Forum - 06-15-2012, 11:30 PM
Active records - "smart" select - by El Forum - 06-16-2012, 12:04 AM
Active records - "smart" select - by El Forum - 06-20-2012, 06:48 PM
Active records - "smart" select - by El Forum - 06-20-2012, 10:20 PM
Active records - "smart" select - by El Forum - 06-23-2012, 07:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB