mysql match string with start of string in table

后端 未结 2 498
梦毁少年i
梦毁少年i 2021-01-07 19:34

I realise that it would be a lot easier if I could modify the table when it was created, but assuming I can\'t, I have a table that is such as:

abcd
abde
abd         


        
2条回答
  •  余生分开走
    2021-01-07 20:13

    Try this:

    SELECT col1, col2 -- etc...
    FROM your_table
    WHERE 'abffagpokejfkjs' LIKE CONCAT(value, '%')
    

    Note that this will not use an index effectively so it will be slow if you have a lot of records.

    Also note that some characters in value (e.g. %) may be interpreted by LIKE as having a special meaning, which may undesirable.

提交回复
热议问题