1

I have 3 tables (for some reason I need to separate these to 3 tables, Im just joining them using LEFT JOIN)

table1

refno
location

table2

refno
description

table3

refno
imagepath

To delete, I need to issue 3 DELETE statements

DELETE FROM table1 WHERE refno = 'variablehere'
DELETE FROM table2 WHERE refno = 'variablehere'
DELETE FROM table3 WHERE refno = 'variablehere'

Is there a way to DELETE from the 3 tables using a single DELETE statement, I mean can I use something like LEFT JOIN in a DELETE Statement?

Mike'78
  • 51
  • 6
  • What will you be achieving by wanting to do so? – Sandeep Rajoria Jun 03 '14 at 12:40
  • possible duplicate of [Mysql - delete from multiple tables with one query](http://stackoverflow.com/questions/4839905/mysql-delete-from-multiple-tables-with-one-query) – Abhik Chakraborty Jun 03 '14 at 12:41
  • @SandeepRajoria. I just thought issuing 3 statements takes more load with my DB compared with issuing a single statement especially that Im deleting 5000+ rows per table – Mike'78 Jun 03 '14 at 12:42

1 Answers1

0

SQL Fiddle showing an example of the following query:

DELETE a.*, b.*, c.*
FROM table1 AS a, table2 AS b, table3 AS c
WHERE a.refno  = b.refno 
AND b.refno  = c.refno 
AND a.refno  = 'variablehere'
Linger
  • 14,942
  • 23
  • 52
  • 79