Friday, November 18, 2011

Explode mysql select value



Today i have faced again with same problem - I was forced to explode value while selecting in MySQL.

Value of the field looks like - Kaina: 60000 LT (17376 EUR)
And i need this - 60000

So i made the select query:


SELECT
SUBSTRING( SUBSTRING_INDEX(`field`,' LT',1), -7) as `field_sub`
FROM `table`


As you can notice, first i have exploded the field value so it be like - Kaina: 60000
After i removed first 7 symbols.

Done... i got 60000

GL