Using a query result as title of a column

Creating tables and queries

Using a query result as title of a column

Postby salvador » Sat Jun 23, 2018 6:52 pm

I'd like to use the data coming from a query as column name.
Suppose I have two tables:
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
╒═════╕
│ 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
salvador
 
Posts: 7
Joined: Tue Oct 31, 2017 4:05 pm
Location: Italy

Re: Using a query result as title of a column

Postby eremmel » Sat Jun 23, 2018 7:44 pm

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
eremmel
 
Posts: 1037
Joined: Tue Dec 30, 2008 1:15 am

Re: Using a query result as title of a column

Postby Villeroy » Sat Jun 23, 2018 8:08 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27295
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Tables & Queries

Who is online

Users browsing this forum: No registered users and 2 guests