-1

Considering the below Mysql 5 query

select
    a as "col_1",
    b as "col_2",
    c as "col_3"
from my_table

How can I use it as a subquery and return the column name aliases in the format below

Column Names
col_1
col_2
col_3

Nothing comes to mind

  • so, you are trying something akin to reflection (ability to inspect itself) in programming language? afaik, you can get [table's column name](https://stackoverflow.com/a/4165253), but not component of each query sentence. – Bagus Tesa Aug 07 '23 at 13:38
  • 1
    The word "column" refers to a very specific concept in relational databases, it isn't entirely clear if you're using it with such meaning. If you have a hard-coded subquery, you could just make it generate rows rather than columns, so we must be missing some context. – Álvaro González Aug 07 '23 at 14:35
  • If you call your query from a programming langiage, then you can get the column names amd aliases as meta data. However, these are not available in mysql for an ad-hoc query, only for views and tables. – Shadow Aug 07 '23 at 15:21
  • You cannot use subquery's metadata as a datasource. So the thing which you need in cannot be realized. – Akina Aug 07 '23 at 16:47

0 Answers0