Maybe I'm going in the wrong direction with this, so I'd love some pointers on how to approach this differently.
I have multiple MySql database tables with 50+ TEXT fields (categories) each (reason, problem, cause, disposition ... etc.), some (most) of these are null, some aren't, depending on the item they are describing.
I want to convert these to a 'topic', 'text' table instead. for example
item, reason , problem , cause , disposition
0001, null , broken widget, unknown , null
0002, returned, null , customer unhappy, in transit
to
item, topic , text
0001, problem , broken widget
0001, cause , unknown
0002, reason , returned
0002, cause , customer unhappy
0002, disposition, in transit
So, I'm fiddling with a select query, this is what I got so far:
SELECT item, problem AS 'text', 'problem' AS 'topic' FROM my_table
WHERE problem IS NOT NULL;
how would I go about adding the next category? Like
SELECT item, cause AS 'text', 'cause' AS 'topic' FROM my_table
WHERE cause IS NOT NULL;
1: how would I add that to the previous select statement so that it would cover both 'cause' and 'problem'?
2: since there are so many categories, is there a way to avoid the manual labor here and iterate through field names somehow?