SQL Select 'n' records without a Table

前端 未结 8 521
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 03:33

Is there a way of selecting a specific number of rows without creating a table. e.g. if i use the following:

SELECT 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
         


        
8条回答
  •  一生所求
    2020-12-30 03:59

    This is a good way if you need a long list (so you don't need lots of UNIONstatements:

    WITH CTE_Numbers AS (
        SELECT n = 1
        UNION ALL
        SELECT n + 1 FROM CTE_Numbers WHERE n < 10 
    )
    SELECT n FROM CTE_Numbers
    

提交回复
热议问题