Results 1 to 10 of 10
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    Union Query is slow , how to speed up? ( Find duplicates from 2 combined tables)

    I have two tables , CrossSystemData and RequestUpdateData .
    Table RequestUpdate Data have 1000 to 5000 data while CrossSystemData have around 20 000 ++ data .
    I want to find duplicates for both tables so I'm using the "UNION"
    However , it take forever to display the results .
    Is there any way that I can speed the process ?
    Thanks in advance .

    This is query swl statement for Union
    Code:
    SELECT CrossSystemData.[PATIENT_ID], CrossSystemData.[PATIENT_NAME], CrossSystemData.[GENDER], CrossSystemData.[DOB], CrossSystemData.[C_SOURCE], CrossSystemData.[CATEGORY_TYPE]
    FROM CrossSystemData
    UNION ALL SELECT RequestUpdateData.[EXT_PAT_ID], RequestUpdateData.[PATIENT_NAME], RequestUpdateData.[GENDER], RequestUpdateData.[DOB], RequestUpdateData.[C_SOURCE], RequestUpdateData.[CATEGORY_TYPE]
    FROM RequestUpdateData;
    The below sql statement is to find the duplicate values for both tables
    Code:
    SELECT UnionQuery.[PATIENT_ID], UnionQuery.[PATIENT_NAME], UnionQuery.[GENDER], UnionQuery.[DOB], UnionQuery.[C_SOURCE], UnionQuery.[CATEGORY_TYPE]
    FROM UnionQuery
    WHERE (((UnionQuery.[PATIENT_ID]) In (SELECT [PATIENT_ID] FROM [UnionQuery] As Tmp GROUP BY [PATIENT_ID] HAVING Count(*)>1 )))
    ORDER BY UnionQuery.[PATIENT_ID];

    Last edited by fluffyvampirekitten; 10-07-2015 at 09:04 PM.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    What exactly does this mean?
    I want to find duplicates for both tables
    Can you give us an example or two?

  3. #3
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    you have a query which combines data from two tables, then looks to see if the ID occurs more than once in the table.
    Wouldn't be simpler to just have one query which selects each record from the first table and checks to see if the ID occurs IN the second table?
    I'm assuming the ID is a PK and is not duplicated within a single table.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Good guess James.. I was wondering given tables A and B, are we looking for duplicates in A, and/or duplicates within B
    or possibly records in A not in B, or records in B not in A, or records in A and B....

  5. #5
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by JamesDeckert View Post
    you have a query which combines data from two tables, then looks to see if the ID occurs more than once in the table.
    Wouldn't be simpler to just have one query which selects each record from the first table and checks to see if the ID occurs IN the second table?
    I'm assuming the ID is a PK and is not duplicated within a single table.
    Yes, I have a query that combines from two tables and find Duplicate IDs from the combined table .
    I didn't set the ID as a Primary Key because there might be duplicates.

    Example:
    Scenario 1
    Table A
    ID : ABC123
    Name: Ben
    Category : Cross

    Table B
    ID : ABC123
    Name: Ben
    Category : Update

    Final result :
    ID | Name| Category
    ABC123|Ben | Cross
    ABC123|Ben | Update

    Scenario 2
    Table A
    ID :XYZ99
    Name: Apple
    Category : Cross

    ID :XYZ99
    Name: Apple
    Category : Cross

    Table B
    ID : XYZ99
    Name: Appplee
    Category : Update

    Final Result
    ID | Name | Category
    XYZ99| Apple | Cross
    XYZ99| Apple | Cross
    XYZ99| Appplee | Update

  6. #6
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    I'm looking duplicates in within B .
    Records in A and B .

  7. #7
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by orange View Post
    Good guess James.. I was wondering given tables A and B, are we looking for duplicates in A, and/or duplicates within B
    or possibly records in A not in B, or records in B not in A, or records in A and B....
    I'm looking duplicates in within B .
    Records in A and B .

  8. #8
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    so that's why it's taking so long. each record is searching every record of the combined two tables for a duplicate id.
    100 records would be about 100x99 searches. This will go up exponentially with more records.
    Is the ID at least indexed?

  9. #9
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by JamesDeckert View Post
    so that's why it's taking so long. each record is searching every record of the combined two tables for a duplicate id.
    100 records would be about 100x99 searches. This will go up exponentially with more records.
    Is the ID at least indexed?

    Yeah , is there any other approach?

    The ID's are not indexed , will it be faster if the IDs are indexed ?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Indexing will improve speed.
    Fundamental to relational database is the use of Primary keys.

    You could also try UNION (no duplicates) instead of UNION ALL(duplicates and replicates).

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

Similar Threads

  1. Form with two subforms = SLOW PERFORMANCE
    By keviny04 in forum Forms
    Replies: 4
    Last Post: 04-29-2015, 11:55 AM
  2. Replies: 11
    Last Post: 10-22-2014, 07:56 AM
  3. Replies: 0
    Last Post: 08-18-2014, 09:11 AM
  4. Replies: 3
    Last Post: 10-18-2011, 03:08 PM
  5. slow performance with multiple users
    By netgrim in forum Access
    Replies: 4
    Last Post: 05-16-2010, 05:41 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