Mysql comma-separated primary key characters and associated name fuzzy query

The relation_ids in the notice table is composed of ids in the exception_trend table separated by commas. Also fuzzy query based on the name field in exception_trend.

What was considered before is to make a subquery for the name fuzzy query in exception_trend, and then display any element of relation_ids in the subquery to display the records. After searching around, I didn't find the relevant statement, which needs to be implemented by myself.

select n.* from notice as n where n.type = 2 and 
(select group_concat(obj.name) from exception_trend as obj 
where FIND_IN_SET(obj.id,n.relation_ids)) like '%1%'

Temporary solution, the design is still a bit problematic. Use less commas to separate items.

Guess you like

Origin blog.csdn.net/zjy660358/article/details/129044347