Results 1 to 5 of 5
  1. #1
    sgremp1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2014
    Posts
    2

    Query Duplicates

    Hoping someone could help/not sure if it's even possible...



    I have two sets of data, there are duplicates on each side, and they're purposely there. I need an unmatched query with outer joins, but I also need inner joins...

    This is for commission reconciliation, so some accounts have more than one payment which is the reason for the duplicates, and for various other system reasons, not all accounts on each side match up. The company requesting the reconciliation sometimes makes mistakes, or sometimes my company makes a mistake. I need all the matched accounts to show up on the query results, but I also need all the UNmatched accounts to show up. Lets say one table has the following:

    Acct #(table 1)
    11111
    11111
    22222
    33333

    THen another table has:

    Acct#(table 2)
    11111
    22222
    33333
    44444

    I need an end result that looks like this:

    Acct #(table 1)
    11111
    11111
    22222
    33333
    _____

    Acct #(table 2)
    11111
    _____
    22222
    33333
    44444

    So I need blanks in each table where the matching account # should go, but I don't want to delete ANY account # from either table, and I also don't want duplicates from both tables, like the result should not show 3 account 11111. This might be hard to understand and I don't konw if it's really possible,

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Need a dataset of all possible account numbers. If you don't have a table of account numbers, create dataset with a UNION query of the AccountNumber field from both tables.

    Join queries to that dataset.


    BTW, advise to avoid spaces and special characters/punctuation (underscore is exception) in naming convention. Better would be AccountNum or Account_Num.
    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.

  3. #3
    sgremp1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2014
    Posts
    2
    Thanks for your reply. I have tried a union query, the problem is it only returns unique records, I actually need the duplicates in there. So then I did a union all query, then it returns the duplicates, but the duplicates from BOTH tables, so if I have 2 exact records in one table, and 2 exact records in the other, I want it to return me JUST two records, union returns 1, and union all returns 4. But I also still want a blank record inserted where accounts don't match on either side, like if I have 2 of the exact record on one table, and only 1 matching record on the other table, it should still return the two exact matches in the results on one side, but also a blank on the other...hope that makes sense... Thanks.

  4. #4
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    If I understand you correctly, to do the first result in table1 is simple. The result in table2 will require some thinking and maybe some clarification.

    The SQL below should produce what you need for the result #1.

    SELECT table1.[Acct #] FROM table1 WHERE table1.[Acct #] IN (SELECT table2.[Acct #] FROM table2);

    NOTE: You might be able to use the same idea for table2.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Problem with the example for Table2 output is that Table2 account 11111 will match to both of the Table1 account 11111 records. Consider:

    Query1:
    SELECT Table1.AcctNum, Table1.ID, DCount("*","Table1","AcctNum=" & [AcctNum] & " AND ID<" & [ID])+1 AS TCt
    FROM Table1
    ORDER BY Table1.AcctNum, Table1.ID;

    Query2:
    SELECT Table2.AcctNum, Table2.ID, DCount("*","Table2","AcctNum=" & [AcctNum] & " AND ID<" & [ID])+1 AS TCt, *
    FROM Table2
    ORDER BY Table2.AcctNum, Table2.ID;

    Query3:
    SELECT TCt, AcctNum FROM Query1
    UNION SELECT TCt, AcctNum FROM Query2;

    Query4:
    SELECT Query3.AcctNum, Query2.AcctNum
    FROM Query2 RIGHT JOIN Query3 ON (Query2.TCt = Query3.TCt) AND (Query2.AcctNum = Query3.AcctNum)
    ORDER BY Query3.AcctNum;
    Last edited by June7; 08-22-2014 at 10:21 PM.
    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. Duplicates showing up in query
    By BrockWade in forum Queries
    Replies: 7
    Last Post: 01-10-2014, 10:42 AM
  2. help with query returning duplicates
    By BrockWade in forum Queries
    Replies: 7
    Last Post: 12-05-2013, 02:23 PM
  3. Query Returning Duplicates
    By rlsublime in forum Queries
    Replies: 14
    Last Post: 03-25-2013, 11:26 AM
  4. Avoiding duplicates in query
    By theracer06 in forum Queries
    Replies: 1
    Last Post: 08-24-2010, 12:49 PM
  5. Duplicates in Query
    By Dega in forum Queries
    Replies: 1
    Last Post: 05-02-2010, 05:09 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