Using a query result as title of a column

Creating tables and queries
Post Reply
salvador
Posts: 7
Joined: Tue Oct 31, 2017 4:05 pm
Location: Italy

Using a query result as title of a column

Post 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.
Michele Salvador
OpenOffice 4.1.4, LibreOffice 5.4.2.2 on Windows 10
eremmel
Posts: 1080
Joined: Tue Dec 30, 2008 1:15 am

Re: Using a query result as title of a column

Post 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).
It's Microsoft marketing that tells you computers are qualified for non-technicians
W11 22H2 (build 22621), LO 7.4.2.3(x64)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Using a query result as title of a column

Post by Villeroy »

On a form you can make a query result look like a column label.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply