gpt4 book ai didi

mysql delete with select multi conditions

转载 作者:行者123 更新时间:2023-11-30 22:38:48 25 4
gpt4 key购买 nike

有没有办法删除这个特定的列?这是行不通的。尽管 SELECT 在 mysql 中运行良好,但它已经过测试。

DELETE FROM table2
WHERE table2.ID IN (SELECT * FROM table2, table1
WHERE table2.tableID = 2 and table1.level = 1 and table1.ID = 1)

补充一下,table1和table2有列:

table1(table1.id, table1.name, table1.level) 

table2(table2.id, table1.id)

我有两个表:

用户

userid username userleve
1 dani 1
2 mark 2

游戏

 gameid   userid  cluba        clubb     resa   resb
1 1 liverpool chealsea 1 1
2 2 Aston Villa Watford 0 0
3 1 Sunderland Swansea City 2 1

There is no FK between tables and i need to delete 1 row entered by specific user with specific level.

最佳答案

试试这个:

DELETE FROM games
USING games
JOIN users ON games.userid = users.userid
WHERE games.userID = 2
and users.userlevel = 1;

select * from users;

select * from games;

SQL Fiddle Demo

关于mysql delete with select multi conditions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31660931/

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