Solved

Query runs too slowly

Posted on 2013-01-17
3
174 Views
Last Modified: 2013-01-21
Here's the query:

SELECT   *
      FROM NC2 a LEFT OUTER JOIN Actions b ON  a.UniqueID = b.DealerID
      WHERE  NOT EXISTS (
                     SELECT c.DealerID
                     FROM    Actions c
                     WHERE  c.DealerID = b.DealerID
                     AND       c.EventID = 1
       )

It works, but it can take over a minute to return records.  The 2 tables only have a few hundred records each.

What I need it to do is the following:

Select every record in NC2 UNLESS the value of UniqueID in NC2 matches up with a field called DealerID in a table called Actions., and then only if they match and the EventID is equal to 1.

Thanks
0
Comment
Question by:Rush_2112
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38788227
you need a index on Actions table, field DealerID
that should help alot.
after that, please show the explain plan of the query
0
 
LVL 1

Author Comment

by:Rush_2112
ID: 38793651
how do i do an explain plan?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38793676
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simple sql statement 3 57
MySQL Error 3 39
Connect MySql database to wordpress site 3 54
MySQL - Restore Database SQL File 5 41
Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now