Why does “select count(*)” from nothing return 1

前端 未结 1 1692
离开以前
离开以前 2020-12-11 00:31

With SQL Server 2012 :

use master
select *

yields

Must specify table to select from

which is

1条回答
  •  温柔的废话
    2020-12-11 01:04

    SQL Server is (behind the curtain) effectively applying a from to a dummy table, which has only one row. Thus you will get 1 for your count.

    select 'test'
    

    will do the same thing, as an example, return 'test' one time.

    It's like the DUAL table in Oracle, SYSDUMMY1 in DB2, etc.

    As requested, here's a couple of links to MS Connect on this topic:

    Clicky

    More Clicky

    0 讨论(0)
提交回复
热议问题