codecowboy
codecowboy

Reputation: 10095

MySQL use column names from another table

I'm wondering if it is possible to return a result set with column names which are stored in a separate table. Is this possible or do I need a stored_procedure with variables. See link for mysql_dump and description of required resultset:

http://pastie.org/584865

Upvotes: 1

Views: 1003

Answers (1)

derobert
derobert

Reputation: 51137

You'd have to use a stored procedure that'd generate SQL dynamically and then run it. Column names aren't really first-class data in SQL, so you can't do much anything with them. They are determined at query parse time, before executing the query or fetching any data.

I suggest doing it in your app instead. Just have your app display/save/whatever the correct names instead of the database column names.

PS: You are abusing the relational model horribly. Please very carefully consider if you really want that schema. Your schema fails the first normal form. And what is worksheet_type_lookup for? Doesn't worksheets tell you which type?

Upvotes: 2

Related Questions