tags:

views:

260

answers:

2

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  A: 
SELECT DISTINCT stuff 
FROM (
  SELECT RTRIM(SUBSTR(data, 1, LOCATE('(', data) - 1)) AS stuff 
  FROM foo
) t;
hobodave
I will test it out and accept if correct :D
Shahmir Javaid
The RTRIM is optional. It strips trailing spaces from your data.
hobodave
LOCATE('(', data) - 1) Im having probs on that
Shahmir Javaid
some body else voted this up.. Did the answer work for you?
Shahmir Javaid
It works just fine. We can't help you if you just say "Im having problems"
hobodave
+1  A: 

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
Shahmir Javaid