How to remove part of string in mysql?

后端 未结 5 1769
既然无缘
既然无缘 2020-12-15 20:27

In one table of my database I have strings which looks like this one:

sometext-othertext

How to remove the text including dash with SELECT

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 21:30

    have two ways to use troubleshooting this, if you like to display all (only just remove "-" symbol, i recommended use this because have more speed:

    SELECT REPLACE('sometext-othertext','-','');
    

    that syntax change text "-" to "" (empty text because you want just remove that)

    if you want to display only part one (ex :sometext) or just part two (ex :othertext) you can use this, for spliting string:

    SELECT SUBSTRING_INDEX('sometext-othertext', '-', 1);
    

提交回复
热议问题