Results 1 to 4 of 4
  1. #1
    donbrown44 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    2

    Help with 'group by' query

    I would like to create a query that 'groups by' the first two columns, selects the 'max' of the third column, then 'carries over' the information in the last two columns that go along with the same row as 'max' of the third column. See below example input and desired output:

    Input Table
    C1, C2, C3, C4, C5
    Mike, Smith, 10, D1, D2
    Mike, Jones, 50, D1, D2
    Joe, Smith, 60, D1, D2
    Joe, Brown, 10, K1, D2
    Mike, Smith, 20, D1, D2
    Mike, Smith, 30, K1, K2
    Mike, Jones, 60, K1, K2
    Mike, Jones, 40, D1, D2


    Desired output table

    Mike, Smith, 30, K1, K2
    Mike, Jones, 60, K1, K2
    Joe, Smith, 60, D1, D2
    Joe, Brown, 10, K1, D2

    I've figured out how to 'group by' the first two columns and get the 'max' of the third column. I cannot figure out how to 'carry over' the last two columns. Any help would be appreciated... Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Is this what you're after?

    http://www.baldyweb.com/LastValue.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    donbrown44 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    2
    Ahah... two queries - didn't even think of that. Or maybe I was just concentrating too hard on doing everything in one query.

    Thanks for the reply - I'll try the two queries approach and mark this as solved if I get it working.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problem. It can be done in one query, with the first as a subquery, but I find it easier to work with them separately.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. query group by over another group by?
    By gap in forum Queries
    Replies: 2
    Last Post: 07-04-2011, 12:59 AM
  2. Group by query
    By anemoskkk in forum Access
    Replies: 1
    Last Post: 04-16-2011, 07:29 AM
  3. SQL query with SUM, INNER JOIN and GROUP BY
    By BayerMeister in forum Queries
    Replies: 2
    Last Post: 08-14-2010, 12:55 AM
  4. query group by
    By fanfan2 in forum Queries
    Replies: 3
    Last Post: 03-12-2010, 03:07 PM
  5. columns for group detail but not group header?
    By Coolpapabell in forum Reports
    Replies: 0
    Last Post: 08-21-2009, 08:53 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