Thank you both very much for your help.
Dhookom,
the structure of my tables is as follows.
tblARReports
with fields: ReportNumber (primary key), Board, StartDate etc.
tblARComments
with fields: CommentID (primary key), Comment, PositiveNegative
tblARCommentsReported
with fields: CommentReportedID (primary key), ReportID, CommentID
tblBoards
with fields: board (primary key), nac_area.
and NAC Area
with fields: Code (primary key), description
So now that I have a lot of entries for tblARCommentsReported I am trying to do a top 10 ranking of both positives and negatives, by NCArea for those with StartDates of 2004 to 2005.
To do this (and being rather inexperienced) I made a query qryARCommentCountByArea:
Code:
SELECT [NAC area].description, tblARCommentsReported.CommentID, Count(tblARComments.CommentID) AS CountOfCommentID, tblARComments.Comment, tblARComments.PositiveNegative, Year([StartDate]) AS [Year]
FROM ((tblARComments RIGHT JOIN (tblARReports LEFT JOIN tblARCommentsReported ON tblARReports.ReportNumber = tblARCommentsReported.ReportNumber) ON tblARComments.CommentID = tblARCommentsReported.CommentID) LEFT JOIN Boards ON tblARReports.Board = Boards.board) LEFT JOIN [NAC area] ON Boards.nac_area = [NAC area].code
GROUP BY [NAC area].description, tblARCommentsReported.CommentID, tblARComments.Comment, tblARComments.PositiveNegative, Year([StartDate])
ORDER BY [NAC area].description, Count(tblARComments.CommentID) DESC;
I then ranked the above using: qryARRankingsOfCommentsReported20042005
Code:
SELECT A.CommentID, A.Comment, A.PositiveNegative, A.description AS NCArea, A.Year, A.CountOfCommentID, Count(*) AS Rank
FROM qryARCommentCountByArea AS A INNER JOIN qryARCommentCountByArea AS B ON (A.CountOfCommentID<=B.CountOfCommentID) AND (A.PositiveNegative = B.PositiveNegative) AND (A.description = B.description) AND (A.Year=B.Year)
WHERE A.Year>2003 AND A.Year<2006
GROUP BY A.Year, A.description, A.PositiveNegative, A.CountOfCommentID, A.Comment, A.CommentID
ORDER BY A.Year, A.description, 6;
The following query I used to get the top 20 positive and negative comments, by area and year and also identified the exact Board for which those comments were reported. qryARTop20CommentsReported0405Reports:
Code:
SELECT qryARRankingsOfCommentsReported20042005.Year, qryARRankingsOfCommentsReported20042005.NCArea, qryARRankingsOfCommentsReported20042005.Rank, qryARRankingsOfCommentsReported20042005.PositiveNegative, qryARRankingsOfCommentsReported20042005.Comment, qryARRankingsOfCommentsReported20042005.CountOfCommentID, qryARRankingsOfCommentsReported20042005.CommentID, tblARReports.Board, [NAC area].description, Year([StartDate]) AS StartDateYear
FROM qryARRankingsOfCommentsReported20042005 LEFT JOIN (((Boards LEFT JOIN [NAC area] ON Boards.nac_area = [NAC area].code) RIGHT JOIN tblARReports ON Boards.board = tblARReports.Board) RIGHT JOIN tblARCommentsReported ON tblARReports.ReportNumber = tblARCommentsReported.ReportNumber) ON qryARRankingsOfCommentsReported20042005.CommentID = tblARCommentsReported.CommentID
WHERE (((qryARRankingsOfCommentsReported20042005.Rank)<20) AND (([NAC area].description) Like [NCArea]) AND ((Year([StartDate])) Like [Year]))
ORDER BY qryARRankingsOfCommentsReported20042005.Year, qryARRankingsOfCommentsReported20042005.NCArea, qryARRankingsOfCommentsReported20042005.Rank, qryARRankingsOfCommentsReported20042005.PositiveNegative DESC , qryARRankingsOfCommentsReported20042005.Comment;
My original query above was to try and get those Boards who had reported such a comment to be concatenated against those comments/rankings.
I am a bit embarassed to have used so many queries where probably only one or two would be required but as you can probably tell I'm very much a beginner.
I did try your suggestion but the computer sort of froze up...
Thanks for any help.