say I have a table with 2 columns: `title` (VARCHAR) and `type` (VARCHAR)
In this case there is only 4 different `type`'s in the data set (1..4)
I want to perform a select query that breaks up `type` into individual columns, the output would be something like (in the code snippet):
I'm looking for 2 possible solutions, first is a simple SELECT query where I manually define the `type`s, and the second is a query where the `type`s are found and collumns automatically added... both would return the same results...
So for the first option, something to the likes of:
SELECT title, type_1=1 if `type` = 1, type_2=1 if `type` = 2, type_3=1 if `type` = 3, type_4=1 if `type` = 4 FROM table_name
(in my example it doesn't need to return 0 I guess, I just put that there for readability)
The hard part I think is to make this happen without knowing how many types there are.. I have made the `types` collumn VARCHAR as the data could be anything, ie it doesn't have to be integers, but in this example it is..
The purpose of this is to go via an advanced data structure into the perl Module: HTML::Template which I can then use HTML_Templates IF functions like <TMPL_IF type_2><p>it's a drink!</p></TMPL_IF>
title type_1 type_2 type_3 type_4
Hamburger 1 0 0 0
Coke 0 1 0 0
Fanta 0 1 0 0
Bread 0 0 0 1
Milk 0 0 0 1