Get all characters before space in MySQL

后端 未结 3 1846
暖寄归人
暖寄归人 2020-12-08 06:12

I would like to get all the characters in a field before a space

For example, if field1 is \"chara ters\"

I want it to return

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 06:33

    SELECT LEFT(field1,LOCATE(' ',field1) - 1)

    Note that if the string in question contains no spaces, this will return an empty string.

提交回复
热议问题