1

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?

2
  • 1
    I'm guessing you will have to use your programming language to parse that string and pull out the second number. What language are you using? Commented Sep 30, 2014 at 18:25
  • Do you mean second highest number? (OR) second positional number? Commented Sep 30, 2014 at 18:28

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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;

An SQLfiddle to test with.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.