mysql like issue on partial match

2019-06-14 07:51发布

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

3条回答
smile是对你的礼貌
2楼-- · 2019-06-14 08:17
 SELECT group_name FROM test WHERE group_name LIKE '%PCB%'

this is working fine in mysql , check fiddle demo

查看更多
Animai°情兽
3楼-- · 2019-06-14 08:18

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

查看更多
太酷不给撩
4楼-- · 2019-06-14 08:39

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]'
查看更多
登录 后发表回答