MYSQL:删除表“bar”中包含字符串“foo”的所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4249079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MYSQL: delete all rows containing string "foo" in table "bar"
提问by Captain Claptrap
What's the command to achieve this:
MYSQL: delete all rows containing string "foo"
in table "bar"
实现此目的的命令是什么:
MYSQL:删除"foo"
表中包含字符串的所有行"bar"
回答by Byron Whitlock
DELETE FROM bar where
field1 like '%foo%'
OR
field2 like '%foo%'
OR
...
fieldLast like '%foo%'
回答by Paul Dixon
You'll need to explicitly list the columns I think, so something along the lines of...
您需要明确列出我认为的列,因此类似于...
DELETE FROM bar WHERE col1 LIKE '%foo%' OR col2 LIKE '%foo%'....etc
回答by Brent Dunham
Try this query
试试这个查询
delete from [table name] where [column name] like '%[text to find]%'
This will match if the text appears, regardless of position. i.e.
如果文本出现,无论位置如何,这都将匹配。IE
if you were looking for foo, it would match "xfoo
" and "foox
"
如果你正在寻找 foo,它会匹配 " xfoo
" 和 " foox
"
回答by Kent Murra
Normally, you can use the 'LIKE' keyword to perform simple pattern matching: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
通常,您可以使用 'LIKE' 关键字来执行简单的模式匹配:http: //dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
回答by thoaionline
The query and explaination can be found here (see question 2)
可以在此处找到查询和说明(请参阅问题 2)
You may also need to change the comparative condition to "like" condition.
您可能还需要将比较条件更改为“喜欢”条件。
回答by shajeer
delete from bar where field1 like '%foo%' OR field2 like '%foo%' OR ... fieldLast like '%foo%'