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 statement so the result to be just sometext?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Return the substring before the first occurrence of the delimiter “-“:
SELECT SUBSTRING_INDEX('foo-bar-bar', '-', 1) as result;Outputs result = “foo”
You can replace 1 with the numbers of occurrences you want before getting the substring
SELECT SUBSTRING_INDEX('foo-bar-bar', '-', 2) as result;Outputs result = “foo-bar”
Reference: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index