1

I want to remove the all part of characters after the specific character in mysql column. But i need that mentioned removable character. I have searched but everything the mentioned characters also removed.

For Example:

Tracding Company Pvt Ltd. - Welecome Home

Need output:

Tracding Company Pvt Ltd.

If i use Ltd. with substring_index then the ltd. also removed.

Please someone help with this.

3

1 Answer 1

1

Just increase the index by the length of the substring you search, in your example 'Ltd.' is 4:

SELECT LEFT('Tracding Company Pvt Ltd. - Welecome Home', INSTR ('Tracding Company Pvt Ltd. - Welecome Home', 'Ltd.') + 4)

Another option is to use the CONCAT() function to add the missing value back:

SELECT CONCAT(SUBSTRING_INDEX('Tracding Company Pvt Ltd. - Welecome Home', 'Ltd.', 1), 'Ltd.')

EDIT: Corrected based on comments

Sign up to request clarification or add additional context in comments.

3 Comments

Instead of 4 you could use length('Ltd.') in case the search string is a variable.
@adambg, I am getting the result as only "4" but i need "Tracding Company Pvt Ltd."
Fixed the answer to better reflect the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.