1

I currently am deleting by a manually constructed query, but there should be a better way to do this.

$query = "DELETE FROM {$table1} ";
$query .= "WHERE col1 = '$col1' ";
$query .= "AND table2_id in ";
$query .= "( SELECT id from {$table2} where col2=$col2 )";
db_query($query)->execute();

How do I do this using db_delete?

Table2 has a covering index, so this should be done in one query.

2

I think your current way is that fine for multiple table handle like that. From this Delete from Multiple Tables using db_delete link you can see that:

db_delete takes a single string parameter to define which table the query is to be run against. There's no scope to provide more than one table at a time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.