gpt4 book ai didi

MYSQL - 使用连接删除查询

转载 作者:可可西里 更新时间:2023-11-01 06:35:01 24 4
gpt4 key购买 nike

我已经检查了回答的问题。但是,解决方案对我不起作用。

DELETE FROM TEST2
INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2
WHERE TEST1.FIELD1 = 22;

当我执行此查询时,我在 phpmyadmin 中收到以下错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near 'INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2' at line 2

我累了。我需要帮助。提前致谢。

最佳答案

这应该有效:

DELETE T
FROM TEST2 T
INNER JOIN TEST1 on TEST1.FIELD2 = T.FIELD2
WHERE TEST1.FIELD1 = 22;

Sample Fiddle Demo

我想你也可以用 IN 来完成:

DELETE FROM Test2
WHERE Field2 IN (
SELECT Field2
FROM Test1
WHERE Field1 = 22)

关于MYSQL - 使用连接删除查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15026368/

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