Hi Guys,
I've built a kind of user forum in my database and there's a functionality that's supposed to show how many posts ("comments" in my db) has got each thread ("productSteps" in my db) and how many posts are new for current user. So it should say something like:
Code:
Thread1 - 10 comments (3 new)
To enable this I have 2 tables (there are more but these ones seem to be important for this thread):
- "tbComments" that contains all comments' content
- "tbCommentsSeen" that contains all users' ids of those who already seen this comment
- "tbProductSteps" that contains all productSteps (think about those as threads for simplicity)
Take a look:

Here's complete SQL:
Code:
SELECT Count(tbComments.commId) AS CountOfcommId, tbProductSteps.ProductStepId, Count(IIf([tbCommentSeen].[userId]=whoIsLogged(),1,Null)) AS CommentsSeen, tbProductSteps.ProductId
FROM (tbComments RIGHT JOIN tbProductSteps ON (tbComments.productId = tbProductSteps.ProductId) AND (tbComments.stepId = tbProductSteps.StepId)) LEFT JOIN tbCommentSeen ON tbComments.commId = tbCommentSeen.commId
GROUP BY tbProductSteps.ProductStepId, tbProductSteps.ProductId;
"CountOfcommId" it's supposed to show all comments written to particular thread. Instead, it counts how many times comment was read. If there's only 1 comment but read 4 times it will show 4 instead of 1. I think I need to use subquery to get only distinct values of commId but I have none experience with subqueries and so far I've spent 2 days trying to figure out a solution. I really appreciate any help.
Robert