Results 1 to 4 of 4
  1. #1
    cbenisch is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    28

    MS Access Distinct Query that returns multiple fileds for each record

    I have a query in access that pulls fields from multiple tables to pull together information in one place or record set if you will. I then create other queries to use this data set. I need to create a distinct query that will look at all the records and return only those with a distinct File As field. But I want to have it return all fields in each record.

    Example



    Current Query Coaches

    File As First Name Last Name Team Position...
    Smith, Bob Bob Smith T1 Head Coach
    Doe, John John Doe T3 Head Coach
    Doe, Sam Sam Doe T4 Head Coach
    Smith, Bob Bob Smith T4 Assistant Coach


    Results
    Smith, Bob Bob Smith T1 Head Coach
    Doe, John John Doe T3 Head Coach
    Doe, Sam Sam Doe T4 Head Coach

    I know it is something with the Max function and an INTER JOIN from what I have found but I just can't seem to create the correct query and format.

    Can anyone help. by giving me an example to query Coaches with the fields shown?

    Thank yo in advance.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It would really help if you would post the SQL of the current Coach query or the dB...

    Is it [File As], [First Name], [Last Name], [Team Position] ??

    Object names with spaces in them is really a BAD idea......

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    ...and how many tables are involved and what they look like. There may be an issue such that neither the DISTINCT nor DISTINCT ROW predicates will help, given that the record you seek to eliminate is Bob Smith, who has different team and position values, and you want to eliminate one. One problem is that you provide no insight into why you eliminate the first vs any other records for Bob Smith. You might need to break this into two parts: where you get a list of distinct values based on some portion of the record, then using those record ID's (assuming you have them), get the rest of the fields based on the ID's. However, as noted, I don't grasp what drives the choice to eliminate one or the other.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    cbenisch is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    28
    I do realize that spaces are bad. I am working over time to correct those.
    This is more of an example. I have many places in the database I would like to use this type of a query. What I am looking to do is create a query that can return a list of records that only has one name where there will be more than one. It does not matter which record is returned for that person but lets say for the example I am looking for the first record with that persons name. In this example I want to do a mail merge to coaches but only want to send one to them even if they coach on multiple teams.

    I don't think that it will actually be distinct to get to the distinct result.

    Here is an example I found on another forum, but I can't seem to apply it to my example and get it to work so I am looking to get an example of how to writing it with my fields.

    SELECT
    MAX(IncrementField) AS MaxOfField1,
    GroupField
    FROM someTable
    GROUP BY GroupField

    SELECT t.*
    FROM someTable AS t
    INNER JOIN [previous query] x
    ON t.Field1 = x.MaxOfField1 AND
    t.GroupField = x.GroupField

    I would like to write this as one query with the subquery so it runs as one query.


    Thanks for the responses.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-30-2016, 05:50 AM
  2. Replies: 1
    Last Post: 12-07-2015, 10:53 AM
  3. Replies: 3
    Last Post: 05-29-2014, 09:50 AM
  4. Replies: 1
    Last Post: 04-30-2014, 01:05 AM
  5. Populate fileds off the last record
    By BorisGomel in forum Access
    Replies: 3
    Last Post: 11-09-2011, 11:37 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