Mysql In子句刪除

2021-05-23 16:02:05 字數 862 閱讀 2935

經測試mysql in子句中只能放一級子查詢,後來改用虛表,測試可用,記錄下~~~

begin 

create table  temptable1  as  (select zpwas.`stock_id` from `zen_products_with_attributes_stock` as zpwas where zpwas.`products_id` in (select zptc.`products_id` from `zen_products_to_categories` as zptc where zptc.`categories_id` =id));

delete from `zen_products_with_attributes_stock`   where `stock_id` in (select stock_id from temptable1);

drop table temptable1;

create table  temptable2  as  select zpa.`products_attributes_id` from `zen_products_attributes` as zpa where zpa.`products_id` in (select zptc.`products_id` from `zen_products_to_categories` as zptc where zptc.`categories_id` =id);

delete from `zen_products_attributes`  where `products_attributes_id` in (select products_attributes_id from temptable2);

drop table temptable2;

end

mysql in子句 MySQL IN 子句

可以使用 in 子句代替許多 or 條件。要想理解 in 子句,還以表 employee tbl 為例,它的所有記錄如下所示 mysql select from employee tbl id name work date daily typing pages 1 john 2007 01 24 2...

MySql in子句 效率低下優化

背景 更新一張表中的某些記錄值,更新條件來自另一張含有200多萬記錄的表,效率極其低下,耗時高達幾分鐘。update clear res set candelete 0 where resid in select distinct resourceid from att attentionresul...

LINQ let子句 join子句

1.let子句 let子句用於在linq表示式中儲存子表示式的計算結果,既let子句建立乙個範圍變數來儲存結果,變數被建立後,不能修改或把其他表示式的結果重新賦值給它。此範圍變數可以在後續的linq中使用 static void main string args new custom var que...