Unfortunately, I have a field column which contains values like
I'm going to write a SELECT statement, whose result would be:
How can I do it in practice, since MySQL does not provide a "split" function?
Use MySQL's SUBSTRING_INDEX
function:
SELECT SUBSTRING_INDEX(field, ',', 1)
However, keeping lists in delimiter-separated strings is generally an inefficient use of a relational database management system like MySQL: it is often better to normalise your data structure by keeping such lists in a separate table of (id, value)
pairs.
You can use MySQL function SUBSTRING_INDEX(str,delim,count)
SELECT SUBSTRING_INDEX(value,',',1) As value FROM ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With