1

I'm new to sql and have a special demand: I have many sql queries (written by others), and I know how many columns these sqls will generate. For example, here is one of the records

select * from some_table

and I known it will generate a table contain 2 columns but I don't known the column names. I want to know if there is a way that performs like this

select [1] as 'Column1', [2] as 'Column2' from some_table

where "[1] as 'Column1'" means the first column in the query result rename to 'Column1', and "[2] as 'Column2'" means the second column rename to 'Column2'.

Update:

I solved the problem using 'UNION ALL', for example

select 'c1' as 'Column1', 'c2' as 'Column2' limit 0
union all
select * from some_table

and 'limit 0' is to remove the row ['c1', 'c2'] from the first query . It will generate table like this

| Column1  | Column2 |
----------------------
| xxxx     | yyyyy   |

Seems works well until now, I will continue verify the correctness.

The solution comes from another question, but I failed to recall the link of that question.

ilu
  • 11
  • 3

1 Answers1

1

Looks like there are already similar questions like this one. According to the response, this is not possible in SQL.

p_efros
  • 301
  • 2
  • 11