jmenezes
jmenezes

Reputation: 1926

Remove everything before the first / in a field and output it

I have data in a MySQL table like this:

us/books/fiction

In MySQL alone, during the select, is it possible to remove what's before the first / so that the final data that's outputted looks like this:

books/fiction

I have searched but could not find any function in MySQL that could do this.

I tried this, but it leaves the / before. I'm trying to do it without the /

select substring(url, instr(url, '/')) from myTable;

Upvotes: 0

Views: 27

Answers (1)

Tobias
Tobias

Reputation: 1682

Just add +1, to also get rid of that / in your substring:

select substring(url, instr(url, '/') + 1) from myTable;

Upvotes: 1

Related Questions