Skip site navigation (1) Skip section navigation (2)

different results using count(x)

From: Raimon Fernandez <coder(at)montx(dot)com>
To: PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org>
Subject: different results using count(x)
Date: 2009-09-09 06:34:20
Message-ID: D1D05BDE-8B65-4D8D-B00A-917971633863@montx.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,


What's the difference between:

SELECT count(id) FROM scanns WHERE tipus='esc'; => 11235
SELECT count(pages) FROM scanns WHERE tipus='esc'; => 11165
SELECT count(*) FROM scanns WHERE tipus='esc'; => 11235

Why are some rows that aren't included in the count(pages) SELECT ?

There are not NULL values in the pages field:

SELECT count(pages) FROM scanns WHERE tipus='esc' AND pages IS NOT  
NULL; => 11165
SELECT count(pages) FROM scanns WHERE tipus='esc' AND pages IS NULL;  
=> 0

And I think the three SELECTS should return the same rows number ...


thanks for your help,

r.


In response to

Responses

pgsql-novice by date

Next:From: Raimon FernandezDate: 2009-09-09 10:16:08
Subject: Re: different results using count(x)
Previous:From: Michael WoodDate: 2009-09-08 22:47:26
Subject: Re: problem loading sql to database?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group