mysql查询数据的同时对它进行删除操作

2018-06-04 10:06:43

今天遇见一个问题,需要把mysql数据库里面的 商品主表 和它的每一个条目对应不上的数据给全部删除(数据如下图);也就是整理一下数据库里的数据保证数据的可用;

但是出现了问题; 我是先查出来productId 然后判断主表里的哪些productId不在这些productId里面直接删除,之前是这个样子写的

delete from wy_product_v1 where productId not in(select wy_product_v1.productId from wy_product_v1,wy_product_item where wy_product_v1.productId=wy_product_item.productId);

报错

MySQL中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

但是改成下面写法就可以了:

delete from wy_product_v1 where productId not in(

select w.productId from(

select wy_product_v1.productId from wy_product_v1,wy_product_item where wy_product_v1.productId=wy_product_item.productId

) w

);

  • 2020-04-01 10:21:20

    Vue extend $mount 构造器详解

    本节介绍两个 Vue.js 内置但却不常用的 API——extend 和 $mount,它们经常一起使用。不常用,是因为在业务开发中,基本没有它们的用武之地,但在独立组件开发时,在一些特定的场景它们是至关重要的。

  • 2020-04-01 15:36:52

    CSS3中的transition属性详解

    transition: property duration timing-function delay transition属性是个复合属性,她包括以下几个子属性: transition-property :规定设置过渡效果的css属性名称 transition-duration :规定完成过渡效果需要多少秒或毫秒 transition-timing-function :指定过渡函数,规定速度效果的速度曲线 transition-delay :指定开始出现的延迟时间

  • 2020-04-02 17:02:25

    vue怎么能像jquery那样获得数据

    有时候我们需要获得动态的元素,但是我们没法直接用vue语法,vue一共了当前组件的对象,我们可以避免使用document.get...之类的。