Results 1 to 2 of 2
  1. #1
    frozendmj is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    4

    Select 5 highest values

    Hi, I am trying to get my query show five highest numbers of accidents,e.g.



    postcode AccidentCount
    NG7 12
    NG8 10
    SW12 5

    so far i've got this:

    SELECT Job.Postcode,
    COUNT ([Job].[JobType]) AS AccidentCount
    FROM Job
    WHERE JobType='Accident'
    GROUP BY Postcode;

    and it gives me a nice list of postcodes and the corresponding counts of accidents. i was thinking of adding a subquery

    (SELECT JobType AS AccidentCount
    FROM Job
    WHERE JobType='Accident'
    ORDER BY AccidentCount DESC LIMIT 0,5)

    so my final query is:

    Code:
    SELECT Job.Postcode,
    COUNT ([Job].[JobType]) AS AccidentCount
    (SELECT JobType AS AccidentCount
    FROM Job
    WHERE JobType='Accident'
    ORDER BY AccidentCount DESC LIMIT 0,5) 
    FROM Job
    WHERE JobType='Accident'
    GROUP BY Postcode;
    but it doesn't work. could anyone please help me to get it right? Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Look here and Top n Per Group

    http://allenbrowne.com/subquery-01.html

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

Similar Threads

  1. Selecting highest value across several fields
    By megabrown in forum Queries
    Replies: 19
    Last Post: 10-28-2014, 01:16 AM
  2. Query to return only the row containing the highest date.
    By eric.opperman1@gmail.com in forum Queries
    Replies: 4
    Last Post: 03-22-2011, 08:42 PM
  3. Replies: 3
    Last Post: 01-04-2011, 07:06 PM
  4. select statement inside values?
    By hung_ko in forum Access
    Replies: 4
    Last Post: 01-01-2011, 10:06 PM
  5. Replies: 5
    Last Post: 11-02-2010, 10:41 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