0

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 ..

2
  • the table names between DELETE and FROM should not be there. dev.mysql.com/doc/refman/8.0/en/delete.html Commented May 17, 2018 at 19:31
  • WARNING: Whenever possible use prepared statements to avoid injecting arbitrary data in your queries and creating SQL injection bugs. These are quite straightforward to do in mysqli and PDO where any user-supplied data is specified with a ? or :name indicator that’s later populated using bind_param or execute depending on which one you’re using. Commented May 17, 2018 at 19:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.