Results 1 to 13 of 13
  1. #1
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7

    Query to return one record from a field that has multiple records for a customer

    I have a table that I am querying off of, that for some of our customers has more then one entry. I am looking for a formula or a condition that will have it return the data with the first letter of the alphabet only and not multiple letters. Here is the data I'm working with:



    Record Key ID Type Description State
    383326 C Alien Registration
    413064 A Driver's License NY
    413067 A Driver's License NY
    413067 D Other Identification NY
    413068 A Driver's License NY
    413097 B Passport
    413100 A Driver's License NY
    413100 D Other Identification NY
    413115 B Passport
    413218 D Other Identification NY
    430565 C Alien Registration NY


    I want it to only return the following:


    Record Key ID Type Description State
    383326 C Alien Registration
    413064 A Driver's License NY
    413067 A Driver's License NY
    413068 A Driver's License NY
    413097 B Passport
    413100 A Driver's License NY
    413115 B Passport
    413218 D Other Identification NY
    430565 C Alien Registration NY


    I'm still somewhat new to this world of data grooming and I've tried a couple of different things, but haven't been able to figure it out yet. Any help would be appreciated, thanks in advance!!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you just need to set criteria value of "A" in Type ID column in your query.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    That looks like you want only the A records or only the License records. Can apply a filter for those parameters.

    SELECT * FROM tablename WHERE [Type ID] = "A";

    SELECT * FROM tablename WHERE [Description ID] = "License";

    Advise no spaces in naming convention.
    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.

  4. #4
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    The problem is that some people don't have an A, they may have only a B (Passport), C (Foreign Id), or D (other ID) So I would need that data to return for those customers. Sorry I didn't explain it great, I was having a hard time putting it into words.

  5. #5
    NOEL71 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    9
    I agree with bob fitz

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Maybe TOP N qualifier will work, review http://allenbrowne.com/subquery-01.html#TopN

    or

    SELECT * FROM tablename WHERE [Type ID] = DMin("[Type ID], "tablename", "[Record Key]=" & [Record Key]);

    Is Record Key a number field?
    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.

  7. #7
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    I updated my original post to try to better explain what I was trying to do. I don't only want the "A"'s or only Driver Licenses since not everyone has that option and it would not return the letters for the other customers. I just want the "A"'s for people where either that is the only option for them or for people with multiple letters, including an "A" to return only that A for that specific customer.

    I hope that makes a little more sense!!

  8. #8
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    No, all of the fields are text fields...

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Text fields will need apostrophe delimiters for the parameter, data/time uses # character.

    "[Record Key]='" & [Record Key] & "'"
    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.

  10. #10
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    Ok, I'm going to give that a try this morning. Hopefully a fresh mind helps too

  11. #11
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Are you trying to get the first Alpha (sorted ID Type) record for each customer?

    If that is true, just sort the records (Record Key and ID Type). Then using "Group BY" and "First" of "ID Type" should give you what you need.

    SELECT customers.[Record Key], First(customers.[ID Type]) AS [FirstOfID Type], First(customers.Description) AS FirstOfDescription, First(customers.State) AS FirstOfState
    FROM customers
    GROUP BY customers.[Record Key]
    ORDER BY customers.[Record Key], First(customers.[ID Type]);

  12. #12
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    That TOP N subquery worked out. Thank you for pointing me in the right direction, I was trying to do too much in one shot!!

  13. #13
    pixar1264 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    7
    Quote Originally Posted by lfpm062010 View Post
    Are you trying to get the first Alpha (sorted ID Type) record for each customer?

    If that is true, just sort the records (Record Key and ID Type). Then using "Group BY" and "First" of "ID Type" should give you what you need.

    SELECT customers.[Record Key], First(customers.[ID Type]) AS [FirstOfID Type], First(customers.Description) AS FirstOfDescription, First(customers.State) AS FirstOfState
    FROM customers
    GROUP BY customers.[Record Key]
    ORDER BY customers.[Record Key], First(customers.[ID Type]);
    Ahh...seeing this shows me where I went wrong when I tried that query. I did not do the sort when I had picked to order it by first. Mental note has been made, thank you for your input lfpm062010!!

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

Similar Threads

  1. Replies: 6
    Last Post: 01-12-2014, 03:11 AM
  2. Replies: 2
    Last Post: 09-06-2013, 06:41 AM
  3. Replies: 11
    Last Post: 04-15-2013, 11:58 AM
  4. Replies: 5
    Last Post: 08-29-2011, 05:17 PM
  5. Replies: 1
    Last Post: 12-10-2009, 08:41 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