简体   繁体   中英

MySQL query to find occurence of one field into another

I want to find all rows form one table where one field is contained into another field. For example:

样本表

It seems simple:

SELECT * FROM MyTable WHERE name LIKE CONCAT('%', parent_names, '%')

I need 1-st and 3-rd row from this query, but the above doesn't work!

Use INSTR()

SELECT * FROM MyTable 
WHERE instr(parent_names, name) > 0

交换列,

WHERE parent_names LIKE CONCAT('%', name, '%')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM