Page 1 of 1

Using a query result as title of a column

Posted: Sat Jun 23, 2018 6:52 pm
by salvador
I'd like to use the data coming from a query as column name.
Suppose I have two tables:

Code: Select all

my_table
┌──────┐
│ data │
├──────┤
│  1   │
│  2   │
│  3   │
└──────┘

my_second_table
┌─────────────┐
│ column_name │
├─────────────┤
│     foo     │
└─────────────┘
This is a pseudo-SQL query (giving a syntax error):

Code: Select all

SELECT "data" AS ( SELECT "column_name" FROM "my_second_table" ) FROM "my_table"
The result I'd like to get is the value foo as header of the column:

Code: Select all

╒═════╕
│ foo │
╞═════╡
│  1  │
│  2  │
│  3  │
└─────┘
How can I obtain this?
I'm using HSQLDB version 1.8.

Re: Using a query result as title of a column

Posted: Sat Jun 23, 2018 7:44 pm
by eremmel
Is not possible. The column name is static and should be known at query parse time (the moment that the query is offered to the database engine).

Re: Using a query result as title of a column

Posted: Sat Jun 23, 2018 8:08 pm
by Villeroy
On a form you can make a query result look like a column label.