简体   繁体   English

mysql删除条件查询

[英]mysql delete query with condition

i have this query .. Delete in more than one table .. but If there a field does not have content in any table, it does not delete anything 我有这个查询..在多个表中删除..但是如果某个字段在任何表中都没有内容,它不会删除任何内容

$sql = " DELETE 
            property,
            unit,
            maintenance,
            report,
            owner
         FROM 
            property,
            unit,
            maintenance,
            report,
            owner           
        WHERE 
            property.id = '".$_REQUEST['property']."'
        AND
            unit.property = property.id
        AND
            unit.id = maintenance.unitid
        AND 
            report.maintenance = maintenance.id 
        AND 
            property.id = owner.property 
        "; 

SO , what conditions can i use it in the query to skip this problem .. 所以,我可以在查询中使用什么条件来跳过此问题..

You will want to look at transactions for this. 您将需要查看此事务 This is a typical (but costly ) way to perform this kind of operation. 这是执行这种操作的一种典型(但成本很高)的方法。

Alternatively, you could create a stored procedure and check that all the criteria are appropriate before executing the delete. 或者,您可以创建一个存储过程,并在执行删除操作之前检查所有条件是否合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM