If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Query taking forever

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-10, 18:43
JehanJaleel JehanJaleel is offline
Registered User
 
Join Date: Oct 2010
Posts: 1
Query taking forever

Hi all,


The following query is taking forever to run on DB2...

select count (*) from SONG_KNOWLEDGE_BASE where SONG_CD not in (select SONG_CD from SONG)

It looks simple. I have heard that NOT IN should not be used, is this true. Can someone help me rewrite this query?

Thanks much,
Jehan
Reply With Quote
  #2 (permalink)  
Old 10-26-10, 00:04
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
You could try something like this, it should perform better
Code:
select count (*)
  from SONG_KNOWLEDGE_BASE  skb
where not exists (select 1 
                           from SONG s
                        where skb.SONG_CD =s.SONG_CD)
Having indexes on SONG_CD will help as well.
Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On