Home » SQL & PL/SQL » SQL & PL/SQL » Count(1) and count(*)
Count(1) and count(*) [message #532677] Thu, 24 November 2011 00:27 Go to next message
sb0024297
Messages: 46
Registered: June 2010
Member
Hi,

can you tell me the difference between count(1) and count(*). As i know count(*) will give number of rows irrespective of null and count(1) will not count the null.

But i am confuse by the below result. My Oracle version is 10 g.

SQL> select * from t1;

A B C
---------- -------------------- --------------------
1 2 3
2
5

SQL> select rownum,a.* from t1 a;

ROWNUM A B C
---------- ---------- -------------------- --------------------
1 1 2 3
2 2
3 5
4

SQL> select count(1) from t1;

COUNT(1)
----------
4

SQL> select count(*) from t1;

COUNT(*)
----------
4

SQL> select rownum,a.* from test1 a;

ROWNUM COL
---------- ----------
1 1
2 2
3 3
4
5 4

SQL> select count(1) from test1;

COUNT(1)
----------
5


SQL> select count(*) from test1;

COUNT(*)
----------
5
Re: Count(1) and count(*) [message #532680 is a reply to message #532677] Thu, 24 November 2011 00:55 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
The number of times that this question has been asked on the internet can be counted in the thousands (at least!) Do a google search on count(*) v count(1). In fact, just use the orafaq search facility, it's been asked here many many times too. There are many, many answers out there. If you find conflicts and are still confused, come back and ask for clarification.
Re: Count(1) and count(*) [message #532696 is a reply to message #532680] Thu, 24 November 2011 01:32 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
can you tell me the difference between count(1) and count(*)

Summary of the answers: none
(but the fact that those that use count(1) does not understand what is count(*) and stupidly copy others code without trying to think)

Regards
Michel
Re: Count(1) and count(*) [message #532697 is a reply to message #532680] Thu, 24 November 2011 01:33 Go to previous message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1156159920245
Previous Topic: Another Stored Trigger issue
Next Topic: how to update another table using trigger
Goto Forum:
  


Current Time: Fri Dec 26 07:23:34 CST 2025