我在where条件中使用“not like”时遇到mysql select问题。表中有15k条记录。 col1 列中有 3k 条记录的值为“test”。
这个选择效果很好:
select
*
from
`table`
where
`col1` like 'test'
已选择 3000 行。这是正确的。
但是如果我尝试这个选择:
select
*
from
`table`
where
`col1` not like 'test'
选择了 0 行,而我预计有 12000 行。
如有任何想法,我将不胜感激?
试试这个
select * from table where col1 NOT LIKE '%test%';
如果您要像在查询中一样进行精确比较,则可以使用
NOT EQUAL
select
*
from
`table`
where
`col1` != 'test'
所以我解决了我的问题:
where ifnull(column,'') not like 'value'
试试这个
SHOW TABLES WHERE col1 NOT LIKE '%test%'
可能缺少%
select
*
from
`table`
where
`col1` not like '%test%'
尝试不使用`
select
*
from
table
where
col1 not like '%test%'
我正在执行类似于以下的查询:
select col from my_table where not like 'some_text%'
当我期待一些结果时,它没有返回任何结果。
原来下划线需要转义
select col from my_table where not like 'some\_text%'