Results 1 to 9 of 9
  1. #1
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97

    counting zip codes as duplicates when first 5 digits are the same

    Hey all,

    I have this query:
    Code:
    SELECT * INTO KeepThese
    FROM final_output_summary_judgment AS f LEFT JOIN (SELECT t.fullName FROM final_output_summary_judgment AS t GROUP BY t.fullName HAVING Count(t.fullname)>=6)  AS Ex ON f.fullName=Ex.fullName
    WHERE Ex.fullname Is Null;
    Although it is supposed to remove any duplicates, it doesn't realize that where the 5 digit zip codes are the same that these should count as duplicates, but it doesn't count them as duplicates because they are not the same:
    Code:
     
    Schmidt,James    6800 NW 24 TER    FORT LAUDERDALE    FL    33309    
    Schmidt,James    6800 NW 24 TER    FORT LAUDERDALE    FL    33309-1412
    Is there a way to get it so that it keeps only one of these records only because the first five digits match of the zip code and all the other fields match. I would only want to preserve the record with the longer zip code in these types of situations.



    Thanks for response.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    could you use distinctrow i wonder?

    Code:
    select distinctrow field1, field2, field3, etc, etc, etc..., left([zipcode], 5)
    
    from table (join statements)
    
    where instr([zipcode], "-") = 0
    I can't remember, but I don't think distinctrow works with just one table, so that accompanying left join might be fine.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    ajetrumpet 's suggestion will do it, but need to change distinctrow to distinct.

  4. #4
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    I tried this:
    Code:
    SELECT DISTINCT fullName, addresses, cities, us_states_and_canada, zip_codes INTO final_output
    FROM (SELECT possibles.fullname, PrepareForDuplicateCheck.addresses, PrepareForDuplicateCheck.cities, PrepareForDuplicateCheck.us_states_and_canada, PrepareForDuplicateCheck.zip_codes FROM possibles, PrepareForDuplicateCheck WHERE instr(PrepareForDuplicateCheck.zip_codes, "-") = 0 and INSTR(PrepareForDuplicateCheck.names_1, possibles.fullname) > 0   Or   INSTR(PrepareForDuplicateCheck.names_2, possibles.fullname) > 0)  AS [%$##@_Alias];
    And it still came back with this:
    Code:
            fullName addresses cities us_states_and_canada zip_codes
     Serrano,Sergio 6528 NW 1 ST MARGATE FL 33063-5102     
    Serrano,Sergio 6528 NW 1 ST MARGATE FL 33063
    when all i needed was this:
    Code:
    Serrano,Sergio6528 NW 1 STMARGATEFL33063-5102
    Thanks for response.

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Obviously, you didn't following what Aje said.

    Please try following query:

    SELECT distinct possibles.fullname, PrepareForDuplicateCheck.addresses, PrepareForDuplicateCheck.cities, PrepareForDuplicateCheck.us_states_and_canada, left(PrepareForDuplicateCheck.zip_codes,5) FROM possibles, PrepareForDuplicateCheck WHERE instr(PrepareForDuplicateCheck.zip_codes, "-") = 0 and INSTR(PrepareForDuplicateCheck.names_1, possibles.fullname) > 0 Or INSTR(PrepareForDuplicateCheck.names_2, possibles.fullname) > 0

  6. #6
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Actually, I didn't explain myself well.

    This query doesn't work:

    SELECT DISTINCT uniSelectedContacts.addresses,uniSelectedContacts. cities,uniSelectedContacts.us_states_and_canada,un iSelectedContacts.zip_codes,uniSelectedContacts.Th eName FROM uniSelectedContacts WHERE instr(uniSelectedContacts.zip_codes, "-") = 0

    If I have these records:
    TheName addresses cities us_states_and_canada zip_codes
    Doe,Jane 333 1st ave Coral Florida 33311
    Doe,Jane 333 1st ave Coral Florida 33311-1234
    Smith,John 111 3st ave Key West Florida 33123
    Bacon,Joe 222 2st ave Saturn Florida 11122
    Bacon,Joe 222 2st ave Saturn Florida 11122


    I would only want it to return:
    TheName addresses cities us_states_and_canada zip_codes
    Doe,Jane 333 1st ave Coral Florida 33311-1234
    Smith,John 111 3st ave Key West Florida 33123
    Bacon,Joe 222 2st ave Saturn Florida 11122

    The above query is flawed because if zip code doesn't contain "-", the record will not be returned. The reason why "-" is in the query is because IF there are two records where the TheName, addresses, cities, us_states_and_canada are all identicial, but zip is identical except for one with 33311 and one with 33311-1234, then I only want to preserve record with 33311-1234. However, in all other cases, where there is no duplicate of TheName, addresses,cities,us_states_and_canada, and zip_codes (the first five digits, that is), then I do want to preserve the record with first five digits. Now if there are two records identical and all shapes and form, then I just want to return one of them, doesn't matter which, since all fields are identical.

    Thanks for response.

  7. #7
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    that will be more simple:
    SELECT uniSelectedContacts.addresses,uniSelectedContacts. cities,uniSelectedContacts.us_states_and_canada, max(uniSelectedContacts.zip_codes) as zip_codes,uniSelectedContacts.Th eName FROM uniSelectedContacts
    group by
    uniSelectedContacts.addresses,uniSelectedContacts. cities,uniSelectedContacts.us_states_and_canada,un iSelectedContacts.Th eName

  8. #8
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Thanks for response. I'm strangely getting duplicates where everything is same. I'm not sure if it's fault in query or I'm appending rows together later that happen to be duplicates.

  9. #9
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Quote Originally Posted by johnmerlino View Post
    Thanks for response. I'm strangely getting duplicates where everything is same. I'm not sure if it's fault in query or I'm appending rows together later that happen to be duplicates.
    Another way to approach this could be:

    ;Make another field in your table, call ZIP5 for example
    ;create an UPDATE query to fill this new field with
    Left(yourZipField,5)
    ;Now ZIP5 will have a 5 digit zip
    ; use the ZIP5 field to resolve the duplicates
    Just my 2 cents....

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

Similar Threads

  1. codes for working days error
    By Harry in forum Programming
    Replies: 21
    Last Post: 10-15-2010, 02:32 PM
  2. Finding subsequent codes
    By Rixxe in forum Queries
    Replies: 8
    Last Post: 09-15-2010, 02:44 AM
  3. rounding digits
    By giladweil in forum Access
    Replies: 1
    Last Post: 09-01-2010, 03:11 AM
  4. basic query codes
    By joms222 in forum Queries
    Replies: 1
    Last Post: 03-20-2009, 11:31 AM
  5. Replies: 1
    Last Post: 09-01-2006, 03:49 PM

Tags for this Thread

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