Why does "select count(*)" from nothing return 1

count, sql, sql-server, sql-server-2012

Solution

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

Problem

With SQL Server 2012 : ``` use master select * ``` yields Must specify table to select from which is exactly what I would expect. But the funny thing is that ``` use master select count(*) ``` returns 1. Can someone explain to me what is counted here? Edit : And possibly include sources...

Original source