Results 1 to 4 of 4
  1. #1
    pvanryzin is offline Novice
    Windows Vista Access 2002 (version 10.0)
    Join Date
    Mar 2009
    Posts
    7

    Smallest in group

    I need to find the youngest kid of each last name

    Anderson Susie 19
    Anderson Bob 12
    Anderson Lenny 15
    Billings George 8
    Cooper Sandy 10
    Cooper Andrew 12
    Donzi Alicia 8
    Donzi Rachel 12

    I need to get back

    Anderson Bob 12
    Billings George 8
    Cooper Sandy 10
    Donzi Alicia 8

    I thought this would be trivial but I just can't seem to crack this one.

    Thanks in advance


    Pierette

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    Your first issue is to split the first and last names into two seperate columns/fields then group by the surname and use minimum on the age field/column.

    To get the first word in the string you can do the following

    Surname:Trim(Left([FullName],InStr([Full Name]," ")))

    David

  3. #3
    pvanryzin is offline Novice
    Windows Vista Access 2002 (version 10.0)
    Join Date
    Mar 2009
    Posts
    7
    The names and ages are already in separate fields. I was trying to solve the problem exactly as you described (group by lastname, min of age). But when I set up the query to allow grouping, it insists on grouping all of the fields and then doesn't work. If I remove the Group By for those fields I don't want to group, I get the error message "you tried to execute a query in which FirstName is not an aggregate field" (or some such thing).

    So in the query I removed all fields except LastName and Age and grouped by LastName and did a min on Age and it did the right thing. Problem is, I don't have any of the additional data in the resulting query that I would like to have (FirstName, Team, ContactInfo, etc). I can't join it against the main table to get this info because LastName isn't a unique key ..... although I suppose LastName and age are unique but geeez - what an ugly way to do it - isn't there anything more straighforward? Like you , I thought I would be able to "carry along" the additional fields in the query without having them effect the result. Have you run into this delimna before?

  4. #4
    I-am-me is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    2
    Do another join query that joins the new resulting query and the original table. In the design view, link last name to last name and age to age, then double click on the link between them and choose the option "only values in table 2 but not table 1" or something of that sort - the option that says you only want the last names of your second table.

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

Similar Threads

  1. Problems with [Group by] in SQL
    By GeedieZ in forum Access
    Replies: 1
    Last Post: 08-14-2009, 03:34 AM
  2. option group in form
    By mawa4492 in forum Forms
    Replies: 1
    Last Post: 08-05-2009, 02:49 PM
  3. How do I group & average at the same time?
    By B20Pete in forum Queries
    Replies: 1
    Last Post: 07-07-2009, 12:53 PM
  4. Group By
    By SMAlvarez in forum Access
    Replies: 0
    Last Post: 10-28-2008, 04:40 PM
  5. Top 2 by group
    By griz in forum Access
    Replies: 0
    Last Post: 05-25-2008, 07:10 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