Reputation: 177
I have column contain a string like that :
"https://www.youtube.com/watch?v=R3-kfnKmDVc"
I want to select this column but get string like that "R3-kfnKmDVc". How do?
Upvotes: 0
Views: 48
Reputation: 46
You can use:
SELECT SUBSTRING('https://www.youtube.com/watch?v=R3-kfnKmDVc', (SELECT LOCATE('?v=', 'https://www.youtube.com/watch?v=R3-kfnKmDVc') + 3));
-> usage in select:
select SUBSTRING(url_name, LOCATE('?v=', url_name) + 3) from table;
Thank You
Upvotes: 0
Reputation: 1269763
If you want the part of the string after the last =
, you can do:
select substring_index(col, '=', -1)
In the event that the string may not contain an '='
:
select (case when col like '%=%' then substring_index(col, '=', -1) end)
Upvotes: 4
Reputation: 7769
By getting the id only you are not improving the performance, so you can simply fetch it from DB then use regex functions to get the id of the youtube link.
Upvotes: 0