mysql: find rows which have a field that is a substring of “string”

前端 未结 4 736
猫巷女王i
猫巷女王i 2021-01-23 10:21

is there a way to write an sql query that finds all rows where the field value is a substring of a given string.

Example:

table names

Name      |      N         


        
4条回答
  •  不思量自难忘°
    2021-01-23 10:47

    If one of Name or Nickname has to be found within the text use

    SELECT *
    FROM names
    WHERE instr("who is Rohit", Name) > 0
       OR instr("who is Rohit", Nickname) > 0
    

    No index can be used for that, so it might take long for large tables.

提交回复
热议问题