smartmouse
smartmouse

Reputation: 14404

Make SQL query that rename output entries

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

Answers (3)

manocha_ak
manocha_ak

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

This is what you want right?

select distinct SUBSTRING_INDEX(value,'_',1) from category;

SQLFIDDLE

Upvotes: 1

Strawberry
Strawberry

Reputation: 33945

Something to think about...

SELECT SUBSTRING_INDEX('germany_2nd_bundesliga','_',1);

Upvotes: 1

Related Questions