Reputation: 11
I have a table with 3 columns:
number | number2 | string
________________________________________________________________
1 | 2 | 0 423 0 2 0 4 2 1 423 521
So, how to get a result like this? :
1, 2, 423
Where 423 is the second number in the string?
Upvotes: 1
Views: 329
Reputation: 181077
You can always use string functions to remove the first value, and cast the rest to int;
SELECT number,
number2,
CAST(SUBSTR(string, LOCATE(' ', string)) AS SIGNED) number3
FROM mytable;
Upvotes: 0
Reputation: 312219
mysql doesn't have a built-in function to split strings, but could MacGyver something up with substring_index
:
SELECT `number`, `number2`,
SUBSTRING_INDEX(SUBSTRING_INDEX(`string`, ' ', 2), ' ', -1)
FROM my_table
Upvotes: 1