How to select multiple rows filled with constants?

后端 未结 15 1048
夕颜
夕颜 2020-11-29 17:08

Selecting constants without referring to a table is perfectly legal in an SQL statement:

SELECT 1, 2, 3

The result set that the latter retu

15条回答
  •  悲&欢浪女
    2020-11-29 17:22

    In MySQL, you can do: values (1,2), (3, 4);

    mysql> values (1,2), (3, 4);
    +---+---+
    | 1 | 2 |
    +---+---+
    | 1 | 2 |
    | 3 | 4 |
    +---+---+
    2 rows in set (0.004 sec)
    

    With MySQL 8, it is also possible to give the column names:

    mysql> SELECT * FROM (SELECT 1, 2, 3, 4) AS dt (a, b, c, d);
    +---+---+---+---+
    | a | b | c | d |
    +---+---+---+---+
    | 1 | 2 | 3 | 4 |
    +---+---+---+---+
    

提交回复
热议问题