Here is my query:
SELECT user.*, @UserID:=user.uid,
(SELECT count(c1) FROM (
SELECT COUNT(*) AS c1 FROM user_group
WHERE user_group.uid=@UserID
GROUP BY user_group.uid
) x1) AS x2
FROM user
Problem is that @UserID in not passed to sub-query
how about using
JOIN? I think the result is the same as what you want. And I’m guessing that you want to get the total number of group the user has. Right?