Select without FROM, but with multiple lines

How can I create a table with two rows and two columns without selecting from an existing table? What I'm looking for is a select statement that returns,

eg.

id | value --------- 1 | 103 2 | 556 
+4
source share
4 answers

Use UNION

 SELECT 1 as id, 103 as value UNION SELECT 2 as id, 556 as value 

See this SQLFiddle

+9
source

You can use UNION ALL . Which is the best choice, then UNION

 SELECT 1 as id, 103 as value UNION ALL SELECT 2 as id, 556 as value 
+2
source

Sybase answer, try something like this in mysql

 select "1" as id,"103" as value union select "2" ,"556" 

Result

id | value
----------
1 | 103
2 | 556

+1
source

If you do not want to hardcode the data in the SELECT statement, you will need to select from the table.

0
source

Source: https://habr.com/ru/post/1442948/


All Articles