In MySQL, I want to be able to search for '31 - 7', when another value = '7 - 31'. What is the syntax that I would use to break apart strings in MySQL? In PHP, I would probably use explode(' - ',$string) and put them together. Is there a way to do this in MySQL?
Background: I’m working with sports scores and want to try games where the scores are the same (and also on the same date) – the listed score for each team is backwards compare to their opponent’s database record.
The ideal MySQL call would be:
Where opponent1.date = opponent2.date
AND opponent1.score = opponent2.score
(opponent2.score would need to be opponent1.score backwards).
MYSQL has no
explode()like function built in. But you can easily add similar function to your DB and then use it from php queries. That function will look like:Usage:
The example above will return
apple.I think that it will be impossible to return array in MySQL so you must specify which occurrence to return explicitly in
pos. Let me know if you succeed using it.