mysql 不喜欢不工作

问题描述 投票:0回答:7

我在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 行。

如有任何想法,我将不胜感激?

mysql select sql-like
7个回答
6
投票

所以我解决了它。问题出在数据上,而不是在请求上。我没有意识到

not like
条件不适用于
NULL
值。

http://sqlfiddle.com/#!2/17270/2


2
投票

试试这个

select * from table where col1 NOT LIKE '%test%';

2
投票

如果您要像在查询中一样进行精确比较,则可以使用

NOT EQUAL

select
   *
from
   `table`
where
   `col1` != 'test'

1
投票

所以我解决了我的问题:

where ifnull(column,'') not like 'value'


0
投票

试试这个

SHOW TABLES WHERE col1 NOT LIKE '%test%'

0
投票

可能缺少%

select
   *
from
   `table`
where
   `col1` not like '%test%'

尝试不使用`

select
   *
from
   table
where
   col1 not like '%test%'

0
投票

我正在执行类似于以下的查询:

select col from my_table where not like 'some_text%'

当我期待一些结果时,它没有返回任何结果。

原来下划线需要转义

select col from my_table where not like 'some\_text%'
© www.soinside.com 2019 - 2024. All rights reserved.