gpt4 book ai didi

mysql - 使用单个 Delete 语句删除多个表

转载 作者:行者123 更新时间:2023-11-30 23:00:57 25 4
gpt4 key购买 nike

我有 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 的东西吗?

最佳答案

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'

关于mysql - 使用单个 Delete 语句删除多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24015366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com