I apologize if this is a dumb or simple question, and I have tried searching for it, but was unable to find a solution; I suspect I simply don’t know the name for this kind of an operation.
I have a MySQL database with a “card” table.
Cards have a casting cost, which may contain between 0 and 5 colors. I want to update every entry in the cards table to include 5 columns, each a boolean for each of the possible colors. So I would need a short algorithm which would parse the colors in a card, then populate the 5 boolean color values accordingly.
I can imagine how to do this with a PHP script, but I thought there must be some way to do it with pure MySQL. Am I mistaken, or is there a name for this type of script?
I understand your question to mean that your
cardtable currently has a column calledcasting costthat contains a set of colours, e.g.'red,green'or'blue,orange,yellow'and that you are looking for a query that yields boolean columns indicating whether each possible colour is in thecasting cost?If so, MySQL’s
FIND_IN_SET()function should give you what you’re after:If you want to permanently change the table to include such columns: