0

If i have data in my MySQL like this

table:

data(TEXT)

foo (hal)

foo (dave)

bar (dave)

bar(dave)

And i want to do This Query

SELECT DISTINCT(data) FROM table;

Now this will return the table as listed above. But i want to do is some sort of replace so that my return query should look like this

SELECT DISTINCT(data) FROM table Replace(data, "(xxxx)", "");

So the Query returns

  • foo
  • bar

Obviously the data is not replaced because the Brackets are important, its just replaced for the query

If this can be done is there performance pitfals in this

2
  • can you post your table schema and maybe some sample data so we have a better understanding of what you are trying to do. Also, it sounds like from what you posted, you may be better off with a LIKE query. REPLACE will definitely impact performance Commented Aug 8, 2009 at 17:55
  • As shown above. The table name is 'table' and it has one column 'data' Where the fields are shown above Commented Aug 8, 2009 at 18:02

2 Answers 2

2
SELECT DISTINCT stuff 
FROM (
  SELECT RTRIM(SUBSTR(data, 1, LOCATE('(', data) - 1)) AS stuff 
  FROM foo
) t;
Sign up to request clarification or add additional context in comments.

3 Comments

The RTRIM is optional. It strips trailing spaces from your data.
LOCATE('(', data) - 1) Im having probs on that
It works just fine. We can't help you if you just say "Im having problems"
1

This worked for me for the above problem. Thanks hobodave, you did put me to the right direction

SELECT DISTINCT(SUBSTRING_INDEX(data, '(', 1)) AS tag FROM table

Comments

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.