Query performance issue - Not in

95 views Asked by At

The query below is created by someone else but is running long so need to improve the performance. Can you please suggest me a better way to do?

Select * from ps_vendor G where G.vendor_id NOT IN (SELECT vendor_id 
                               FROM   ps_voucher_line 
                               WHERE  vendor_id <> '70830' 
                                      AND cntrct_id <> ' ' 
                                      AND vendor_id NOT IN (SELECT vendor_id 
                                                            FROM   ps_cntrct_hdr 
                                                            WHERE 
                                          cntrct_type = 'AP')) 
1

There are 1 answers

5
Mohtisham Zubair On

Please try with inner join condition like display below

Select G.* from ps_vendor G 
       inner join ps_voucher_line  pvl
            on G.vendor_id = pvl.vendor_id and pvl.vendor_id  <> '70830'
        inner join ps_cntrct_hdr pch
            on  (pch.vendor_id <> pvl.vendor_id and pch.cntrct_type = 'AP')
    where pv.cntrct_id <> ' '  

Try different variations in joining condition!!

Good is that you have sub query to verify results.