Mysql使用NOT IN/LIKE选择查询来检索数据
我需要使用select query在mysql中获取数据,如下所示Mysql使用NOT IN/LIKE选择查询来检索数据,mysql,Mysql,我需要使用select query在mysql中获取数据,如下所示 Select tid from abc where abc.parameter not like '%DONE%' 但返回参数列具有%DONE%值的数据 为了更好地理解,我在这里给出了示例数据 tid parameter value *************************** 1 abc 123 1 def 456 1 ghi
Select tid from abc where abc.parameter not like '%DONE%'
但返回参数列具有%DONE%值的数据
为了更好地理解,我在这里给出了示例数据
tid parameter value
***************************
1 abc 123
1 def 456
1 ghi 789
我需要在def不在的地方检索tid 您的tid是相同的,返回的数据可能是正确的,但是由于tid中的模糊性,您觉得您得到了错误的结果。Schema 询问 看起来和我预料的一样
注意,如果为空,则NOT IN是危险的。您必须非常了解这些数据,否则use NOT EXISTS我在任何地方都看不到任何操作。我确信我理解-您正在尝试选择任何行中都没有
def
参数的tid
s,对吗?是@Mureinik您是对的,如果您有解决方案,那么很好,否则请提供一些与您的查询匹配的样本数据,因为您正在搜索的样本数据不像“%DONE%”,但在您的样本数据中没有任何像“DONE”这样的值。如果服务器使用区分大小写的匹配,请检查服务器的编码!?请尝试此abc.parameter COLLATE拉丁语1\u瑞典语\u ci与“%DONE%”不同这可能会有所帮助:)一些没有定义字符串的tid,我想从abc中检索那些tid。选择id,tid,其中abc.parameter不象“%three%”;++-----++------++++id | tid | parameter++------++------++------++1 | 1 | 2 | 1 | 2 | 3 | 1 | 3 | 4 | 2 | 1 | 5 | 2 | 2++------+它应该检索ID5的值
create table abc
( id int auto_increment primary key,
tid int not null,
parameter varchar(20) not null,
value int not null
);
insert abc(tid,parameter,value) values (1,'abc',123),(1,'def',456),(1,'ghi',789);
select id,tid from abc where abc.parameter not like '%DONE%';
+----+-----+
| id | tid |
+----+-----+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
+----+-----+
select id,tid from abc where abc.parameter not like '%abc%';
+----+-----+
| id | tid |
+----+-----+
| 2 | 1 |
| 3 | 1 |
+----+-----+