Explode and compare value in a Select?

0

In my MySql I have the following column data_id it stores values in this 120-01-01 format, as would be SELECT that would make a EXPLODE in that field and check if the first value of array than in case would 120 , hit with the value typed?

Using only PHP would be easy to give explode('-', $data_id) and then compare if the first key hits the desired value, but that would compel me to search all the values in the table before, which is out of the question for obvious reasons, so I would like to know if it is possible to do the same within SELECT .

Note: this column is not a date field, but a varchar

    
asked by anonymous 30.05.2017 / 21:35

1 answer

0

I believe this is what you want:

SELECT SUBSTRING_INDEX($data_id, '-', 1)
    
31.05.2017 / 03:21