Select distinct first words of a field

前端 未结 2 2078
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 21:06

i would like to be able to do a select query, taking only the distinct first words of the string, excluding the last one. If not clear, here is the result i\'d like to have

2条回答
  •  醉话见心
    2021-01-16 21:16

    You can reverse the string to find the first space " "

    SQL Demo

    SELECT DISTINCT RTRIM(REVERSE(SUBSTRING(REVERSE(`model`),LOCATE(" ",REVERSE(`model`)))))
    FROM Table1
    

    OUTPUT

提交回复
热议问题