Changing SQL NOT IN to JOINS -


enter image description here

hello guys,

our aim script insert missing pairs of product - taxcategory in intermediate table (producttaxcategory)

the following script correctly working trying find way optimize it:

insert producttaxcategory     (producttaxcategory_taxcategoryid,producttaxcategory_productid) select      taxcategoryid     ,productid  product pr cross join taxcategory tx pr.productid not in  (     select producttaxcategory_productid     producttaxcategory )  or pr.productid in  (     select producttaxcategory_productid      producttaxcategory )  , tx.taxcategoryid not in  (     select producttaxcategory_taxcategoryid      producttaxcategory      producttaxcategory_productid = pr.productid  ) 

how can optimize query ?

try (full statement now):

insert producttaxcategory     (producttaxcategory_taxcategoryid,producttaxcategory_productid) select taxcategoryid, productid  product pr cross join taxcategory tx not exists        (select 1 producttaxcategory          producttaxcategory_productid     = pr.productid         ,   producttaxcategory_taxcategoryid = tx.taxcategoryid) 

exists (select 1 ... id=...) better alternative in (select id ... ) constructs.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -