0

i have table :

table : mytable

id  name
1   abcd ( dljdf
2   kjlkjkldjf ( ( ( ;dfld )

I want to remove string starting from character '('.

Result would look like

id  name
1   abcd
2   kjlkjkldjf

I tried using Trim Function but it did not give me required result

Any help plz.

1

2 Answers 2

1
SELECT SUBSTRING_INDEX(name, '(', 1) FROM test;

UPDATE test
    SET name = TRIM(SUBSTRING_INDEX(name, '(', 1));

(assuming you want to get rid of the space, too)

0

To peform this task, I did the following

Created my table:

CREATE TABLE test (id INT, name VARCHAR(25));

Inserted test data:

INSERT INTO test VALUES (1, 'abcd ( dljdf');
INSERT INTO test VALUES (2, 'kjlkjkldjf ( ( ( ;dfld )');

Then, using the SUBSTRING function and the LOCATE function, I ran this query:

SELECT SUBSTRING(name, 1, (LOCATE(' ', name) - 1)) AS MyResult FROM test;

Result:

MyResult
---------
abcd
kjlkjkldjf

If you wish to include the blank between the end of the first alphabetical string and the left bracket, substitute ( for (space) in the locate part of the above query. If this isn't suitable, please expand on your requirements.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.