Irvıng Ngr
Irvıng Ngr

Reputation: 438

Select data between dashes from a table

I hope somebody has any idea how to get data from a table using a query but just the characters between the dashes " - ". I cant use substr because is limited to a few characters. I have a few hours trying to figure out but i cant. Please help.

      Data
+-------------+
|   MYTABLE   |
+-------------+
|  PSL-9-1    |
|  PSL-9-2    |
|  PSL-10-1   |
|  PSL-10-2   |
|  PSL-500-1  |
|  PSL-8600-1 |
+-------------+

Desired output:

+-------------+
|   MYTABLE   |
+-------------+
|     9       |
|     9       |
|     10      |
|     10      |
|     500     |
|     8600    |
+-------------+

Upvotes: 1

Views: 73

Answers (1)

rishipuri
rishipuri

Reputation: 1528

substring_index is your friend

SELECT substring_index(substring_index(value, '-', 2), '-', -1) FROM data;

SQLFiddle Link

Upvotes: 3

Related Questions