Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用1个查询执行此操作?_Php - Fatal编程技术网

Php 如何使用1个查询执行此操作?

Php 如何使用1个查询执行此操作?,php,Php,我试图从这1个查询中进行查询,但没有得到结果。我认为这会奏效 delete from table1 where user_id = ... delete from table2 where user_id = ... delete from table3 where user_id = ... delete from table4 where user_id = ... 还有另一个可能有效的解决方案: DELETE table1.*, table2.*,table3.* FROM table1

我试图从这1个查询中进行查询,但没有得到结果。

我认为这会奏效

delete from table1 where user_id = ...
delete from table2 where user_id = ...
delete from table3 where user_id = ...
delete from table4 where user_id = ...
还有另一个可能有效的解决方案:

DELETE table1.*, table2.*,table3.* FROM table1, table2, table3 
WHERE table1.user_id=? and table2.user_id=? and table3.user_id=?; 

无论如何,您可以在表上使用“删除级联”选项定义
,然后从父表中删除记录将删除子表中的所有记录。

您使用什么库访问MySQL?你试过什么?你想做什么?若要从表中删除数据,请改为截断表..伙计们。。。他正在处理多张桌子!:)@Jan Hančiči尝试了这个方法:从table1、table2、table3、table4中删除table1.user_id=。。。和表2.user_id=。。。和表3.user_id=。。。和表4.user_id=。。。这是php页面上的sql查询。我已经在本地检查过了,两种方法都很好。您使用的是什么SQL DB和什么版本?我以为您使用的是MySQL>=4.1,希望您理解需要将“?”替换为用户id值:)
DELETE FROM table1, table2, table3 
USING table1 
    INNER JOIN table2 USING(user_id) 
    INNER JOIN table3 USING(user_id) 
WHERE table1.user_id= ?