SQL - Find complete word in text

后端 未结 2 928
耶瑟儿~
耶瑟儿~ 2021-01-05 22:23

I have a text column in one of my tables in a MySql DB. i want to get all the records that have a specific word in the text column. for example:

ID,BIO
1, \"         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-05 22:55

    use LIKE operator. like so:

    select * from table1 where BIO LIKE '%cto%'  
    

    the '%' indicates a wildcard (meaning- any set of chars).
    if you want to find only records that begin with 'cto', use: 'cto%'.
    if you want only records that contain cto as a full word (i.e with spaces around it), use:

    BIO LIKE '% cto %' or BIO LIKE 'cto %' or BIO LIKE 'cto %'  
    

    (the two Or's i've added are for cases when 'cto' appears at the beginning / end of the string)

提交回复
热议问题