MySql SELECT AS - Append all field names

前端 未结 4 1582
傲寒
傲寒 2021-01-17 11:32

I\'d like to do something like this:

SELECT table.id AS prefix_id, table.name AS prefix_name

... and have the prefix added dynamically to a

4条回答
  •  心在旅途
    2021-01-17 11:53

    I can imagine a situation where this could be useful if you have multiple data models in a list that you need to populate from a single SQL query.

    It should be possible to use DESCRIBE or SHOW COLUMNS on those tables before the SELECT query. That way, you know all of the field names for each table. This doesn't help with any potential field name conflicts though.

    I am not going to comment on if this is a good idea or not. Each developer must decide where to draw the line between flexibility, laziness and good practice.

提交回复
热议问题