mysql like issue on partial match

不想你离开。 提交于 2019-12-08 11:22:39

问题


Im having a mysql query like this

SELECT group_name FROM t_groups WHERE group_name LIKE '%PCB%';

The results are

group_name
------------
PCB
Full size PCB

Another query,

SELECT group_name FROM t_groups WHERE group_name LIKE '%PCB-123%';

group_name
-----------
PCB-123

How can i use a query that will show all the three results ?,I mean i need to get all the results that starts or contains PCB


回答1:


use RLIKE

as you have changed the context of your question so below is my updated answer

SELECT group_name FROM t_groups WHERE group_name RLIKE '[PCB]'



回答2:


 SELECT group_name FROM test WHERE group_name LIKE '%PCB%'

this is working fine in mysql , check fiddle demo




回答3:


I have executed your query

SELECT group_name FROM t_groups WHERE group_name LIKE '%PCB%';

Works fine for me . It returned 3 records

Can you explain what type of datatype you have used for group_name column



来源:https://stackoverflow.com/questions/12907712/mysql-like-issue-on-partial-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!