首页 > 代码库 > mysql中delete from in子查询删除失败

mysql中delete from in子查询删除失败

遇到一个情况,想通过表1的id找到表2,删除表2中barcode关联的库存数据,然后一直不能失败,如下:

delete from 库存表 where BARCODE in
(
select BARCODE from 表1 where fmoveid=
(select id from 表2 where PCID=‘SMX2014082604494930‘)

);

解决方式,加别名

delete from 库存表 where BARCODE in
(
select aa.BARCODE from(
    select BARCODE from 表1 where fmoveid=
    (select id from 表2 where PCID=‘SMX2014082604494930‘)
) as aa

);

 

mysql中delete from in子查询删除失败