Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Mon, 05 May 2008 @ 12:45:48 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


Subj:   Re: Difference between count(*) and count(1)
 
From:   McCall, Glenn David

  Can you tell me what is difference between count(*) and count(1) ?  


Did you have a look at the manual? This sort basic thing can be answered by a quick look at the count function in the SQL Functions manual.

* Count(*) counts all occurrences including nulls. This is a row count.

* Count (x) counts all non null occurrences of values in column x. If x has null values, count(x) will be less than count(*).

* Count (1) is like count(x) it will count all null values in a "pseudo column" created by the constant. Since the constant 1 will never be null, this would, like count(*), give you a row count.


Thus with this data in t3:

     X       y
     1       1
     Null    2
     Null    3
     4       4

And this query:

     select count(*), count(x), count(1)
     from t3;

you get:

     4, 2, 4

Regards

Glenn Mc



     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023