Results 1 to 5 of 5
  1. #1
    gap is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    12

    using TOP

    hello,



    i got a query where i am counting the number of something and group the counts for each topic. now using TOP I'm just getting five rows at all and not five rows for each topic. I am also using ORDER BY DESC to get the highest values. how can i combine TOP and GROUP BY to get for each topic just five rows?

    thanks for help,

    gap

  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
    Please show your query, and exactly what you are trying to accomplish.

  3. #3
    gap is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    12
    here is a query:
    Code:
     SELECT TOP 5 t.topic, t.number, t.ID_WoS FROM 
    (SELECT topic, ID_WoS, Count(ID_WoS) AS number FROM table GROUP BY ID_WoS, topic) AS t
    ORDER BY t.topic ASC, t.number DESC;
    i'm counting the ID_WoS and need to group it for ID_WoS and topic.
    i tried different combinations to get the 5 highest numbers for each topic.

    in the example query i am just getting 5 rows for the first topic and not for all of them.

    hope its better to understand.

    thanks,
    gap

  4. #4
    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
    A couple of things.

    Number is a reserved word in Access and may cause you a problem.
    Do you really have a table called table? That may also be a reserved word.

    I'm still not clear on what you want to achieve. You are familiar with the data and the environment, the rest of us rely on you for info.

    Here's a link to a response I gave recently on a question about Top 5
    top 5 based on descending highest number of hospital visits.
    http://www.access-programmers.co.uk/...d.php?t=214997

    Good luck

  5. #5
    gap is offline Novice
    Windows Vista Access 2007
    Join Date
    Jul 2011
    Posts
    12
    hi,
    number and table were just an example in this query.

    thank you for the link, it's close to what i was looking for. I will try to fix my query and in the worst case give more detailed informations.

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

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