GROUP BY troubles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lachlanpearce
    New Member
    • Dec 2011
    • 4

    GROUP BY troubles

    Hi, I'm trying to write a Group By query.
    I have a table that looks like this:

    Code:
    [B][U]label        value        version[/U][/B]
    Fee          25.99        5795
    Term         3            5795
    Terminated   0            5562
    Terminated   1            5563
    Terminated   0            5794
    Terminated   0            5795
    I want to GROUP BY label using a MAX aggregate function on the version column to obtain the following table

    Code:
    [B][U]label        value        version[/U][/B]
    Fee          25.99        5795
    Term         3            5795
    Terminated   0            5795
    I tried the query but it says I need to contain all columns in either the GROUP BY clause or an aggregate function.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Your intention is not a group by at all. Your goal is merely to select the record with the Max revision for each label as opposed to grouping by label. What you should do is take the Max revision for each label and use that to filter for the record you want.

    Comment

    • lachlanpearce
      New Member
      • Dec 2011
      • 4

      #3
      Can you give me an example using the tables in the first post.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        What you're looking for is similar to this thread http://bytes.com/topic/access/answer...ng-latest-date.

        Comment

        • lachlanpearce
          New Member
          • Dec 2011
          • 4

          #5
          Hi, I tried the example but it still didn't work. Can you write a specific example for this question?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Show me what you mean by you tried the example.

            Comment

            Working...