gpt4 book ai didi

mysql - 删除除具有指定条目的行之外的所有行

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

除了非常具体的条目外,我基本上需要删除我的 MYSQL 数据库。我想使用这些行中的数据来防止它们被 delete all 查询删除。

我的 GoogleFu 还不够强大,这是我唯一的起点:

    delete from YourTable 
where id not in
(
select ID
from YourTable
LIMIT 200
)

现在我知道这是删除除 200 个条目之外的所有条目,但当然这不是我想要做的,但它具有我认为我需要的格式。这是一个很好的开始,但我需要停止删除任何包含唯一数据条目的行。有什么建议吗?

最佳答案

简单地使用不等于或不在怎么样?您没有指定标准,但也许这会起作用:

delete from YourTable
where id not in (1, 2, 3, 4, 5);

如果你的条件比较复杂,你可以使用或者:

delete from YourTable
where col1 = 'Lucy' and col2 = 'Ricky' or
col1 = 'Fred' and col2 = 'Irma' or
col1 = 'Thurston' and col2 = 'Lovey';

关于mysql - 删除除具有指定条目的行之外的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25090924/

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