I\'m trying to join two tables here, so I get the total rows for a particular user based on postStatus. The data is correct without the join, but when I add a join, I get weird
Another possible solution:
select
a.userId,
sum(a.postStatus = 0) published,
sum(a.postStatus = 1) inactive,
sum(a.postStatus = 5) recalled,
sum(a.postStatus = 6) deleted,
b.unChecked
from userData a left outer join
(select userId, sum(poststatus = 10) unChecked
from userDataMod
group by userId)
b on a.userId = b.userId
where a.userId = 1;
I think you have to yoin with userid
and postId
select
a.userId,
sum(a.postStatus = 0) published,
sum(a.postStatus = 1) inactive,
sum(a.postStatus = 5) recalled,
sum(a.postStatus = 6) deleted,
sum(b.postStatus = 10) unChecked
from userData a join userdatamod b on a.userId = b.userId and a.postId=b.postId where a.userId = 1;