0
In my Mysql I have the following column data_id
it stores values in this format 120-01-01
, what a SELECT
make a EXPLODE
in that field and checks whether the first value of the array
which in case would be 120
, matches the entered value?
Using only PHP would be easy to give a explode('-', $data_id)
and then compare if the first key matches the desired value, but it would require me to search all the values of 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 the SELECT
.
Note: such a column is not a type field date
, and yes a varchar
Please collaborate with the quality of community content by better elaborating your response. Very short answers will hardly be clear enough to add anything to the discussion. If your response is based on some function or feature of the language/tool, link to the official documentation or reliable material that supports your response. Searching for similar questions in the community can also be interesting to indicate other approaches to the problem.
– Woss
I understand is that in the case of select is simple even, but anyway, explaining, this select that I posted will return the first item before -, which is similar to php explode, to learn more about the operation of SUBSTRING_INDEX, when typing on google several trusted links will appear, one of them being: https://dev.mysql.com/doc/refman/5.7/en/string-functions.html
– Solange