I have these tables:
comments
uid
id
pid
pages
pid
user
users
id
rank
.
.
.
and this query:
SELECT
u.*,
count(p.id) as 'pages',
count(c.id) as 'comments'
FROM
`users` u
LEFT OUTER JOIN `pages` p ON p.user = u.id
LEFT OUTER JOIN `comments` c ON c.uid = u.id
GROUP BY u.id
For some reason it shows 2 comments for a user when he has only 1.
Is there a problem in the query?
The problem is that the user is multiplied by his number of pages, and then by his number of comments. One way to fix that is
count(distinct ..):