A
A
Alexey Nikolaev2018-01-31 00:06:31
MySQL
Alexey Nikolaev, 2018-01-31 00:06:31

Is it possible to name the columns in the resulting set as values ​​from the table?

Goodnight.
There is a table A, with two columns: name and value. I want all value rows to be in the selection, but the name of the columns to be the values. To put it simply, there is a row with name = John Smith and with value = Some value, and I want the result to be a column titled "John Smith", not the name column as it would normally be. The more unique values ​​in the name column, the more columns should be in the resulting set.
Is it even possible? I tried to put a subquery in select expressions (so that the result of the subquery is used as an alias), and a few more options, but it didn’t work out.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2018-01-31
@Heian

It is worth starting with the fact that, regardless of the number of rows, each column has one name.
Accordingly, many names = many columns.
Well, and so - you need to look towards pivot tables
It seems that this has already appeared in MySQL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question