Results 1 to 4 of 4
  1. #1
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91

    Really Really Inefficient Query

    I'm writing a query for a report that checks whether a persons id, which is recorded in one table, appears in a payment list in another table. The code below is what I have generated. It displays the details of the people whose id's do not appear in the payment list for a particular event. The problem is it is really inefficient and can take 10minutes to genereate the query results or the report that is built on top of it. Maybe I've written in completely incorrectly but I gleaned the code from several tutorials. Any help would be extremely helpful.Thanks in advance.




    Code:
    SELECT Donations.DonerLastName, Donations.DonerFirstName, Donations.DonerOrg, Donations.[Address Line 1], Donations.[Address Line 2], Donations.[Address Line 3], Donations.[Address Line 4], Donations.[Address Line 5]
    FROM Donations, PaymentsReceived
    WHERE (((Exists (Select * from PaymentsReceived Where PaymentsReceived.[DonerRegID] = Donations.[Donation ID]))=False))
    GROUP BY Donations.DonerLastName, Donations.DonerFirstName, Donations.DonerOrg, Donations.[Address Line 1], Donations.[Address Line 2], Donations.[Address Line 3], Donations.[Address Line 4], Donations.[Address Line 5], Donations.[Donation ID], PaymentsReceived.EventType
    HAVING (((PaymentsReceived.EventType)=6));

  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,770
    Maybe lack of a JOIN causes the slow performance.

    Maybe:

    SELECT * FROM Donations WHERE [Donation ID] Not IN (SELECT DISTINCT DonerRegID FROM PaymentsReceived);

    How long does that take for a start?

    If you want to show payment info, then try an outer (LEFT or RIGHT) join between Donations and PaymentsReceived along with the GROUP BY and filter parameters.
    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
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    That takes about 10 - 12 seconds to run. That's a massive improvement June. Thanks for that. It was really causing me a headache.

  4. #4
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    If I check for the eventtype field = 2 (or any number) I end up with no results June. Any ideas

    Code:
    SELECT *
    FROM Donations INNER JOIN PaymentsReceived ON Donations.[Donation ID] = PaymentsReceived.DonerRegID
    WHERE (((Donations.[Donation ID]) Not In (SELECT DISTINCT DonerRegID FROM PaymentsReceived)) AND ((PaymentsReceived.EventType)=2));

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

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