php MYSQL 选择 where 字段不包含某个字符串字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25364167/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:48:12  来源:igfitidea点击:

MYSQL select where field does not contain a certain string character

phpmysqldatabasedynamicsitemap

提问by user3468325

I use sql to select all my sites URLs from a table.

我使用 sql 从表中选择我所有的站点 URL。

$sql = 'select * from pages where "myURL field";

However I want to be a little more specific with my query. There are a few duplicate links in my table for example:

但是,我想对我的查询更具体一点。例如,我的表中有一些重复的链接:

about-us
./about-us

I don't want the ./about usfield to be selected. Is there a way of saying:

我不想./about us选择该字段。有没有一种说法:

select * where "myURL field" does not begin with . /

Or should I just forget it and parse using PHP?

或者我应该忘记它并使用PHP进行解析?

回答by Dennis Schepers

SELECT * FROM pages WHERE some_col NOT LIKE './%';

This will fetch all rows where some_col is not starting with ./

这将获取 some_col 不以开头的所有行 ./

回答by Utkarsh Dixit

Use LIKEin mysql to check that it is not starting with ./. Use the code below

LIKE在 mysql 中使用以检查它是否不是以./. 使用下面的代码

SELECT * FROM pages WHERE col_name NOT LIKE './%';

Hope this helps you

希望这对你有帮助

回答by Sahil

select * from pages where my_url NOT LIKE './%';