![]() |
how and where do i add a 'totalCount' results returned
I have the following code that gets all the comments made and lists them in date order where a member either started or has replied to a comment which someone else started.
What I would like to have in the results is a totalCount' in each row that tells me how many results are related to the `itemid`. I know that each result for an item will have the same totalCount number, but this is the results I am after. Any help on this would be much appreciated. Code:
SELECT `c`.`id`, `c`.`dateAdded`, `c`.`itemid`, `c`.`comment`, `c`.`reportedby`, |
Well, I would start by getting rid of that innermost separate SELECT (where userid = 219...and why are there apostrophes around a *NUMBER*???) and then just JOIN to yet another separate counting SELECT:
Code:
SELECT c.id, c.dateAdded, c.itemid, c.comment, c.reportedby, c.userid AS posterId, |
I should note that the query does *NOT* do what you said it does:
Quote:
That's because your INNER JOIN that joins C and X ensures that only the records in C that match the MAX(dateadded) specified by X.dateadded will be found. |
| All times are GMT +1. The time now is 06:26 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.