1

桌子APP

柜台 | 物品
100001 | 圆珠笔  
100002 | 铅笔  
100003 | 证券纸  
100004 | 标记

桌子Purchase_Order

柜台 | 地位
100001 | 是的  
100001 | 是的  
100001 | 是的  
100004 | 不

我想删除表中的所有计数器app100001 purchase_order。我怎样才能做到这一点?

这是我的代码

应用程序.php

<a href="app.php?de='.$row["counter"].'">

if(isset($_GET['de']))
{
$del_id=$_GET['de'];

sql= ...

}
4

4 回答 4

1

一般方法查询如下所示

DELETE a, p
  FROM 
(
  SELECT 100001 counter
) q LEFT JOIN app a 
    ON q.counter = a.counter LEFT JOIN purchase_order p
    ON q.counter = p.counter;

它会删除两个表中的行,即使其中一个表没有行counter = 100001

这是SQLFiddle演示

于 2013-11-12T06:00:58.843 回答
1

尝试以下操作:

DELETE a.*, p.*
FROM app a
LEFT JOIN purchase_order p
    ON p.counter = a.counter
WHERE a.counter = 100001
于 2013-11-12T05:47:15.367 回答
1

尝试这个:

sql= "DELETE FROM a.*, b.* from app a LEFT JOIN purchase_order b 
on a.counter=b.counter where a.counter=".$del_id;
于 2013-11-12T05:56:06.150 回答
1

尝试以下查询

DELETE a.*,b.* FROM app as a LEFT JOIN purchase_order as b ON a.counter=b.counter WHERE a.counter=100001

于 2013-11-12T05:59:07.773 回答