Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column alias for VALUES ( ) syntax

Tags:

sql

derby

db2

Here's some SQL:

select T.*
FROM (
values ( '2014-05-30 17:26:32.749' , 'Casual shirt ' ) , ( '2014-05-30 17:26:32.749' , 'Casual shirt-White-Small ' ) , ( '2014-05-30 17:26:32.749' , 'Casual shirt-Blue-Medium ' ) , ( '2014-05-30 17:26:32.749' , 'Cords ' ) , ( '2014-05-30 17:26:32.749' , 'Bodysuit ' ) , ( '2014-05-30 17:26:32.749' , 'Cords-Black-29W x 28L ' ) , ( '2014-05-30 17:26:32.749' , 'Bodysuit-Black-Petit ' ) , ( '2014-05-30 17:26:32.749' , 'Cords-Brown-29W x 28L ' ) , ( '2014-05-30 17:26:32.749' , 'Classic pleated dress pant ' ) , ( '2014-05-30 17:26:32.749' , 'Classic pleated dress pant-Black-29W x 32L ' ) , ( '2014-05-30 17:26:32.749' , 'Dress shirt ' ) , ( '2014-05-30 17:26:32.749' , 'Dress shirt-White-15 ' ) , ( '2014-05-30 17:26:32.749' , 'Dress shirt-White-16 ' )
) T
;

It returns columns "1" and "2". How to change it so it returns named columns? Is it possible without using sysdummy1 ?

like image 718
basin Avatar asked Feb 22 '26 15:02

basin


1 Answers

You can add the column names to T:

select T.*
FROM (values ( '2014-05-30 17:26:32.749' , 'Casual shirt ' ) ,
             ( '2014-05-30 17:26:32.749' , 'Casual shirt-White-Small ' ) ,
             ( '2014-05-30 17:26:32.749' , 'Casual shirt-Blue-Medium ' ) ,
             ( '2014-05-30 17:26:32.749' , 'Cords ' ) ,
             ( '2014-05-30 17:26:32.749' , 'Bodysuit ' ) ,
             . . .
     ) T(col1, col2);
like image 146
Gordon Linoff Avatar answered Feb 24 '26 06:02

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!