Reputation: 14404
I have table with field category
that contains entries like the following:
germany_bundesliga
germany_2nd_bundesliga
england_premier_leauge
england_championship
spain_liga
spain_liga_adelante
and so on...
i would like to get this output:
gemany
england
spain
...
Is it possible with an SQL query?
Upvotes: 0
Views: 238
Reputation: 902
While this is not totally pretty but in your case you can do
select distinct substr(category, 0, indexof(category)) from TABLE;
In gist
Upvotes: -1
Reputation: 5655
This is what you want right?
select distinct SUBSTRING_INDEX(value,'_',1) from category;
Upvotes: 1
Reputation: 33945
Something to think about...
SELECT SUBSTRING_INDEX('germany_2nd_bundesliga','_',1);
Upvotes: 1