[英]how to filter the data from varchar column mysql
We have data into our database我们的数据库中有数据
id: 1 name: 100 abc
id: 2 name: 200 xyz
id: 3 name: 1000 kku
id: 4 name: 12 yog
id: 5 name: 1 ton
SELECT id from table where name = '${result['name']}'
If someone put into result 100 ABc it will not match because our db has 100 abc, So how can we fix it please guide如果有人输入结果 100 ABc 它将不匹配,因为我们的数据库有 100 个 abc,那么我们如何解决它,请指导
I mean it should return me id : 1 if someone put我的意思是它应该返回我 id : 1 如果有人放
SELECT id from table where name = '100 ABC' or SELECT id from table where name = '100abc'
The typical way you would handle this would be to just lowercase both of the comparison, eg您处理此问题的典型方法是将两个比较都小写,例如
SELECT id FROM table WHERE name = LOWER('100 ABC');
A better approach, however, would be to only store lowercase in the table, and then only pass in lowercase data from your application layer.然而,更好的方法是只在表中存储小写字母,然后只从应用程序层传入小写字母数据。 You could consider using a lowercase collation in MySQL for this, but you could also enforce this from the application.
为此,您可以考虑在 MySQL 中使用小写排序规则,但您也可以从应用程序中强制执行此操作。
SELECT
id
FROM
`table_name`
WHERE
LOWER(REPLACE(`name`, ' ', '')) = LOWER(REPLACE('100 abc', ' ', ''));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.