Results 1 to 2 of 2
  1. #1
    bearsgone is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    4

    Top 20 problem

    Hello
    I have this query below. It should return top 20 names where number of accidents is the highest. Instead I get everybody not just 20. Not sure what is the problem. Please help.

    SELECT TOP 20 staff.[LAST NAME] & ", " & staff.[first NAME] AS [Names], Count(ClientIncidentReportsStaff.[Report ID]) AS Incidents, [Client Incident Reports].Date
    FROM (ClientIncidentReportsStaff INNER JOIN [Client Incident Reports] ON ClientIncidentReportsStaff.[Report ID] = [Client Incident Reports].[Report ID]) INNER JOIN Staff ON ClientIncidentReportsStaff.[Staff Name] = Staff.[Staff ID]


    WHERE (((Staff.[staff id])=[ClientIncidentReportsStaff].[Staff Name]) AND (([Client Incident Reports].Date)>=#10/1/2010# And ([Client Incident Reports].Date)<=#10/31/2010#) AND (([Client Incident Reports].[Restraint Minutes]) Is Not Null))
    GROUP BY staff.[LAST NAME] & ", " & staff.[first NAME], [Client Incident Reports].Date
    ORDER BY Incidents DESC;

  2. #2
    evander is offline Competent Performer
    Windows 7 Access 2003
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    206
    When making complex queries such as yours, you should learn to make them one at a time.

    1. The first query will contain your WHERE criteria.
    2. Using the first query, create the second query and apply your GROUP BY clause.
    3. Using the second query, create the third query and apply TOP 20.
    4. If the above three queries work, consolidate all your queries by substituting an entire SQL clause for the name of the queries and by using the AS keyword.

    Hope this helps. Good luck.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  2. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums