gpt4 book ai didi

MYSQL - 具有 in 子句的删除查询中的语法错误

转载 作者:行者123 更新时间:2023-11-29 04:43:08 27 4
gpt4 key购买 nike

我有一个示例模式,它的 SQL Fiddle 如下:

http://sqlfiddle.com/#!2/6816b/2

这个 fiddle 只是根据 where 子句中的条件查询示例数据库,如下所示:

SELECT *
FROM person p_outer
WHERE age IN
(SELECT age AS age1
FROM person p_inner
WHERE first_name='Anne');
The output of the same is:         ID    FIRST_NAME AGE    GENDER      1    Bob        25       MM      8    Anne       25       FF        

I have a delete query which has a inner query as below:

DELETE
FROM person p_outer
WHERE age IN
(SELECT age
FROM person p_inner
WHERE first_name='Anne');

上述查询的 SQL Fiddle 是:http://sqlfiddle.com/#!2/6816b/3

此查询在 Oracle DB 中正常运行,当我在 MYSQL DB 中运行相同的查询时,出现以下错误:

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     'p_outer   WHERE age IN     (SELECT age     FROM person p_inner     WHERE first_n' at line 2: 

另外MYSQL版本是5.6.13。

如果上述语法存在问题,请告知。

最佳答案

使用这个语法:

DELETE a.*
FROM person a
join person b on a.age = b.age and b.first_name = 'Anne';

fiddle

关于MYSQL - 具有 in 子句的删除查询中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24392020/

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