Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Unanswered: 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

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •