How to select multiple rows filled with constants?

后端 未结 15 885
夕颜
夕颜 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:47

    This way can help you

    SELECT   TOP 3
             1 AS First, 
             2 AS Second, 
             3 AS Third 
    FROM     Any_Table_In_Your_DataBase
    

    Any_Table_In_Your_DataBase: any table which contains more than 3 records, or use any system table. Here we have no concern with data of that table.

    You can bring variations in result set by concatenating a column with First, Second and Third columns from Any_Table_In_Your_DataBase table.

    0 讨论(0)
  • 2020-11-29 17:48
    SELECT 1, 2, 3
    UNION ALL SELECT 4, 5, 6
    UNION ALL SELECT 7, 8, 9
    
    0 讨论(0)
  • 2020-11-29 17:48

    In Oracle

    SELECT
      CASE
        WHEN level = 1
        THEN 'HI'
        WHEN level = 2
        THEN 'BYE'
      END TEST
    FROM dual
      CONNECT BY level <= 2;
    
    0 讨论(0)
提交回复
热议问题