dbTalk Databases Forums  

SQL question - Having count(*)

comp.databases comp.databases


Discuss SQL question - Having count(*) in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ark
 
Posts: n/a

Default SQL question - Having count(*) - 06-23-2004 , 07:46 PM






Using Oracle SQL

Let say I have a table named STUDENT
this table contains the following columns
STNAME, STTELE, STSCHOOL, STAGE, STPROG

now I have the following two queries

1st )

select STNAME, STTELE, STAGE from STUDENT
group by STNAME, STTELE, STAGE
having
COUNT (*) > 4;

2nd)

select STNAME, STTELE, STAGE from STUDENT
group by STNAME, STTELE, STAGE
having
COUNT (STNAME) > 4 and COUNT (STTELE) > 4 and COUNT (STAGE) > 4;


Are those two queries doing EXACTLY the same thing? In other words, in
COUNT(*), does the asterisk replaces all the columns from the table or does
it replace ONLY the columns listed in the GROUP BY?

thnaks in advance for any help



Reply With Quote
  #2  
Old   
Lee Fesperman
 
Posts: n/a

Default Re: SQL question - Having count(*) - 06-24-2004 , 01:05 AM






Ark wrote:
Quote:
Using Oracle SQL

Let say I have a table named STUDENT
this table contains the following columns
STNAME, STTELE, STSCHOOL, STAGE, STPROG

now I have the following two queries

1st )

select STNAME, STTELE, STAGE from STUDENT
group by STNAME, STTELE, STAGE
having
COUNT (*) > 4;

2nd)

select STNAME, STTELE, STAGE from STUDENT
group by STNAME, STTELE, STAGE
having
COUNT (STNAME) > 4 and COUNT (STTELE) > 4 and COUNT (STAGE) > 4;

Are those two queries doing EXACTLY the same thing? In other words, in
COUNT(*), does the asterisk replaces all the columns from the table or does
it replace ONLY the columns listed in the GROUP BY?
They will not produce the same result, assuming at least one grouping has >4 rows, if
that grouping contains a NULL for one of the columns. That is:

+ COUNT(*) counts all subject rows.

+ COUNT(exp) doesn't count those rows where exp evaluates to NULL.

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.