sqlmysqlsubquery

MySQL can values statement columns be named?


I have searched on the forums and failed to find how can one name columns for a values statement subquery.

Here is my query in MySQL:

SELECT *
FROM (VALUES
    ('PPA', 'blah', 30)
    , ('PPB', 'blah blah', 60)
) AS X

Here is what I can do in T-SQL:

SELECT x.a, x.b, x.c
FROM (VALUES
    ('PPA', 'blah', 30)
    , ('PPB', 'blah blah', 60)
) AS x(a, b, c)

Very simple, yet can't find out.

Note: As I know this query can be simplified to no subquery, my question remains as this will be merged into another query for an insert and a left join of mine.


Solution

  • You are almost there just need to add ROW.

    SELECT * FROM (VALUES
        ROW('PPA', 'blah', 30), 
        ROW('PPB', 'blah blah', 60)
    ) AS X (a, b, c);
    

    Result:

    enter image description here

    More about ROW you can read here and here.