Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL how create select with explicit return values

Tags:

sql

select

mysql

How do I select like this:

SELECT * FROM
 (SELECT 11 AS Value UNION
 SELECT 24 AS Value UNION
 SELECT 53 AS Value UNION
 SELECT 124 AS Value UNION
 SELECT 2215 AS Value) AS ValueTable

This query give me a perfect result, just this query is ugly.

How create this just nicely such as:

select 11,24...
select arrray(22,24...)

These don't works just examples.

Thx

like image 658
Cipo Avatar asked Feb 10 '26 21:02

Cipo


1 Answers

Your query is correct. The only thing I can do to make it pretty is remove all the field name declaration after the first one

SELECT * 
FROM   (SELECT 11 AS Value  UNION 
        SELECT 24  UNION 
        SELECT 53  UNION 
        SELECT 124 UNION 
        SELECT 2215) AS ValueTable 
like image 153
Juan Carlos Oropeza Avatar answered Feb 12 '26 15:02

Juan Carlos Oropeza