I don’t know if this is possible or not.
I have Table1 with the following fields.
No
A
B
C
D
I want table2's column names to be table1’s row names (varchar(20) each, all null’s)
A B C D
If I add a row in table1, table2 column should get appended too.
Any suggestions.
There’s some info on a few pseudo solutions in T-SQL (SQL Server) here, some of which may be transferable to MySQL: http://sqlserveradvisor.blogspot.co.uk/2009/03/sql-server-convert-rows-to-columns.html
However there’s no simple method.
The best I could come up with (again in T-SQL) is this dynamic SQL solution:
–EDIT–
I’ve managed to try out a script on MySQL (via the online host here: http://headfirstlabs.com/sql_hands_on/hf01.htm). The below code works with the demo database there, so should work on your table. I made it slightly overcomplicated by having the columns contain data with the column number because I got a bit confused, but hopefully it’s all helpful so I’ve left it in for now.
(simplified MySQL Version)
Hope that helps.