Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 删除除具有指定项的行以外的所有行_Mysql_Rows - Fatal编程技术网

Mysql 删除除具有指定项的行以外的所有行

Mysql 删除除具有指定项的行以外的所有行,mysql,rows,Mysql,Rows,我需要基本上清除我的MYSQL数据库,除了非常具体的条目。我希望使用这些行中的数据来防止“全部删除”查询删除这些行 我的谷歌搜索引擎不够强大,这是我唯一的出发点: delete from YourTable where id not in ( select ID from YourTable LIMIT 200 ) 现在我知道这是删除除200个条目之外的所有条目,但这当然不是我想要做的,但它具有我认为我需要的格式。这是一个很好的开始,

我需要基本上清除我的MYSQL数据库,除了非常具体的条目。我希望使用这些行中的数据来防止“全部删除”查询删除这些行

我的谷歌搜索引擎不够强大,这是我唯一的出发点:

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

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

简单地使用not equals或not in如何?您没有指定标准,但这可能会起作用:

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新手。