MySQL use column names from another table

六眼飞鱼酱① 提交于 2019-12-20 04:22:39

问题


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


回答1:


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?



来源:https://stackoverflow.com/questions/1281520/mysql-use-column-names-from-another-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!