Skip to main content
Tweeted twitter.com/StackDBAs/status/919032688664875009
edited tags
Link
Rick James
  • 79.4k
  • 5
  • 51
  • 117
Source Link
mal
  • 181
  • 1
  • 7

Is it possible to rename the columns of a resultset?

I have two tables joined on an ID.

they might look like this:

table_overview  
| id | version | description |
------------------------------
| 1  | 1.2.3   | new stuff.. |


table_files
| id | type    | file_name   |
------------------------------
| 1  | TEXT    | as.txt      |
| 1  | IMG     | abc.png     |
| 1  | AUDIO   | def.wav     | 

Where the primary key of table_overview is id and the primary key of table_files is id and type.

I want to return a result set where each row contains all of the information, but replace the heading file_name with the type instead, so a row in the result set would look something like this:

| id | version | description | text   | img     | audio   |
| 1  | 1.2.3   | new stuff.. | as.txt | abc.png | def.wav |

Is something like this possible? Or am I better off simply creating the table that way in the first place.
The initial idea was that it should be easy to add new types in the future.