日期:2014-05-16  浏览次数:20850 次

Mysql In子句删除

?

经测试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