1

I have the following join below and I was wanting to know is there a better way to write it as I am getting Unknown table 'id' in MULTI DELETE and I cannot seem to pin point where.

Join:

$query = $dbConnection->prepare('
    DELETE c.id, r.id, s.id,f.id,ip.id,ct.id
    FROM campaigns c
    JOIN campaignsFroms f ON f.id = c.id
    JOIN campaignsRaw r ON r.id = c.id
    JOIN campaignsSubjects s ON s.id = c.id
    JOIN campaignIPTracking ip ON ip.id = c.id
    JOIN campaignTracking ct ON ct.id = c.id
    WHERE c.id = :campaign_id');
$query->execute(array(':campaign_id' => $campaign_id));
Jess McKenzie
  • 8,345
  • 27
  • 100
  • 170
  • 1
    `DELETE` deletes rows. You need to omit fields. Also, if you want to delete row from one table by id you need to omit all other tables. – sectus Oct 27 '15 at 04:00
  • not really a duplicate but related and helpful here: http://stackoverflow.com/questions/4839905/mysql-delete-from-multiple-tables-with-one-query –  Oct 27 '15 at 04:03
  • [the docs are also helpful](http://dev.mysql.com/doc/refman/5.0/en/delete.html) –  Oct 27 '15 at 04:13

1 Answers1

2

Your DELETE statement is incorrect. You should remove the fields.

DELETE 
    FROM campaigns c
    JOIN campaignsFroms f ON f.id = c.id
    JOIN campaignsRaw r ON r.id = c.id
    JOIN campaignsSubjects s ON s.id = c.id
    JOIN campaignIPTracking ip ON ip.id = c.id
    JOIN campaignTracking ct ON ct.id = c.id
    WHERE c.id = :campaign_id'
Chris
  • 4,762
  • 3
  • 44
  • 79