Results 1 to 2 of 2
  1. #1
    MSAccessNewb is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    2

    How Do I Select Distinct on Multiple Columns and Keep The Lowest Values On Others?

    Hi,



    I have a table where I would like to filter certain columns for duplicates (first name, last name), and then take the lowest values in other columns (year, class rank). So for example, here is my data:

    Year Class Rank First Name Last Name
    2006 1 Sarah Jones
    2006 2 Bob Johnson
    2006 3 Glenn Mafoof
    2006 4 Jim Shu
    2006 5 Justin Time
    2007 1 Glenn Mafoof
    2007 2 Jim Shu
    2007 3 Sarah Jones
    2007 4 Bob Johnson
    2007 5 Justin Time
    2008 1 Bob Johnson
    2008 2 Justin Time
    2008 3 Sarah Jones
    2008 4 Jim Shu
    2008 5 Glenn Mafoof
    2009 1 Sarah Jones
    2009 2 Glenn Mafoof
    2009 3 Bob Johnson
    2009 4 Jim Shu
    2009 5 Justin Time

    I would like a query to it to turn into this (ordered by last name):

    Year Class Rank First Name Last Name
    2008 1 Bob Johnson
    2006 1 Sarah Jones
    2007 1 Glenn Mafoof
    2007 2 Jim Shu
    2008 2 Justin Time

    How do I do this? Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    First you want the lowest rank then the lowest year if more than one record at same rank for each name?

    Sounds difficult. Criteria dependent on data in other records of same dataset is the trickiest. Usually requires subqueries.

    Review http://allenbrowne.com/subquery-01.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 05-17-2012, 03:52 PM
  2. Sql code for Distinct column and two other Columns
    By vaiofoxx1 in forum Programming
    Replies: 3
    Last Post: 03-22-2012, 09:24 AM
  3. Count values across multiple columns
    By mkallover in forum Queries
    Replies: 3
    Last Post: 02-06-2012, 12:08 PM
  4. Replies: 1
    Last Post: 11-03-2011, 01:07 AM
  5. Replies: 8
    Last Post: 04-21-2011, 05:29 PM

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