Home > database >  Mysql both string comma-separated matching match to each other are found out
Mysql both string comma-separated matching match to each other are found out

Time:09-17



The above table pids is a string commas;
If I had a string ', 11111113, 37112, 333; Asked the string according to the commas, 11111, 11337, 112333 as long as the string appears inside the pids are query that is to say the above input 'only 11337, 11111113, 37112, 333' contained in the query contains that how to write SQL

CodePudding user response:

The final result is what? 11337?

CodePudding user response:

All pids matching to 11337 in return

CodePudding user response:

 select distinct * from table name where the exists (
Select * from (
SELECT
SUBSTRING_INDEX (SUBSTRING_INDEX (', 11111113, 37112, 333 ', ', ', help_topic_id + 1), ', ', 1) AS num
The FROM
Mysql. Help_topic
WHERE
Help_topic_id & lt; LENGTH (', 11111113, 37112, 333) - LENGTH (the REPLACE (', 11111113, 37112, 333 ', ', ', ')) + 1) t1 where INSTR (pids, num) & gt; 0
)

CodePudding user response:

SELECT * FROM table name where FIND_IN_SET (' 11337 ', pids);

CodePudding user response:

Using MYSQL function INSTR (field name, string)

This function returns a string in a certain position in the content of the field, did not find the string returns 0, otherwise returns location (starting at 1)

SELECT * FROM table name ORDER BY INSTR (pids, '11337') & gt; 0;
  • Related