使用单个Delete Statement删除多个表

时间:2014-06-03 12:37:29

标签: mysql

我有3个表(出于某种原因,我需要将这些表分成3个表,我只是使用LEFT JOIN加入它们)

表1

refno
location

表2

refno
description

表3

refno
imagepath

要删除,我需要发出3个DELETE语句

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

有没有办法使用单个DELETE语句从3个表中删除,我的意思是我可以在DELETE语句中使用类似LEFT JOIN的东西吗?

1 个答案:

答案 0 :(得分:0)

SQL Fiddle显示以下查询的示例:

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'