How does mysql query whether the specified multiple comma-separated values are in comma-separated data

  mysql, question

How does mysql query whether the specified multiple comma-separated values are in comma-separated data
For example, there is a table in table1 with a column called tag. The data in tag is
Tag
——
34,2
10
10,34
10,2
10,34,2
When the query condition tag is 34,10, only the records of the second article (10) and the third article (10,34) are required to be queried.
When tag is 10,2, only the records of Article 2 (10) and Article 4 (10,2) are required to be queried.
Thank you very much

Since MySQL does notSplitFunction, so can only get one.
However, MySQL function cannot return the result set, so it cannotselect xxx()This method is used.
Maybe we can write oneProcedureAccording to the requirements of the subject, I have roughly realized one, perhaps you can refer to it:

DROP PROCEDURE IF EXISTS containsOnly;
 DELIMITER $$
 CREATE PROCEDURE containsOnly(search VARCHAR(600))
 Begin
 DECLARE result varchar(100);
 DECLARE i INT DEFAULT 1;
 DROP TABLE IF EXISTS tmp_table;
 CREATE TEMPORARY TABLE tmp_table (
 tag VARCHAR(100) NOT NULL,
 replacedtag VARCHAR(100)
 );
 
 insert into tmp_table(tag,replacedtag) select tag,replace(concat('|',tag,'|'),',','||') from table1;
 label:LOOP
 SET result = REPLACE(SUBSTRING(SUBSTRING_INDEX(search, ',', i)
 , length (substring _ index (search,',', I-1)) plus 1),',','');
 
 IF result = '' THEN
 LEAVE label;
 END IF;
 
 update tmp_table set replacedtag = replace(replacedtag,concat('|',result,'|'),'');
 SET i=i plus 1;
 
 END LOOP;
 
 select tag from tmp_table where replacedtag='';
 END $$

It is very convenient to call, only need to:

call containsOnly('2,10')