Unix Technical Forum

Count(*) different than record count

This is a discussion on Count(*) different than record count within the MySQL forums, part of the Database Server Software category; --> Can someone explain why the following query will return 80 records: SELECT DISTINCT c.caseid FROM cases c LEFT JOIN ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:18 AM
Bosconian
 
Posts: n/a
Default Count(*) different than record count

Can someone explain why the following query will return 80 records:

SELECT DISTINCT c.caseid FROM cases c LEFT JOIN casespecialty cs ON c.caseid
= cs.caseid LEFT JOIN examspecialty es ON c.caseid = es.caseid WHERE (cs.uid
= 86 OR es.uid = 86)

but when c.caseid is wrapped with Count() the query will return 225:

SELECT DISTINCT Count(c.caseid) FROM cases c LEFT JOIN casespecialty cs ON
c.caseid = cs.caseid LEFT JOIN examspecialty es ON c.caseid = es.caseid
WHERE (cs.uid = 86 OR es.uid = 86)

The correct answer in this case is 80. I'm looking for Count() to return the
correct (desired) total.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:18 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Count(*) different than record count

Bosconian wrote:
> Can someone explain why the following query will return 80 records:
>
> SELECT DISTINCT c.caseid FROM cases c LEFT JOIN casespecialty cs ON c.caseid
> = cs.caseid LEFT JOIN examspecialty es ON c.caseid = es.caseid WHERE (cs.uid
> = 86 OR es.uid = 86)
>
> but when c.caseid is wrapped with Count() the query will return 225:
>
> SELECT DISTINCT Count(c.caseid) FROM cases c LEFT JOIN casespecialty cs ON
> c.caseid = cs.caseid LEFT JOIN examspecialty es ON c.caseid = es.caseid
> WHERE (cs.uid = 86 OR es.uid = 86)
>
> The correct answer in this case is 80. I'm looking for Count() to return the
> correct (desired) total.
>
>


Do you want a distinct count, or a count of distinct items?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:18 AM
Bosconian
 
Posts: n/a
Default Re: Count(*) different than record count

"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:uLidnbqxJNTsf7nYnZ2dnUVZ_smdnZ2d@comcast.com. ..
> Bosconian wrote:
>> Can someone explain why the following query will return 80 records:
>>
>> SELECT DISTINCT c.caseid FROM cases c LEFT JOIN casespecialty cs ON
>> c.caseid = cs.caseid LEFT JOIN examspecialty es ON c.caseid = es.caseid
>> WHERE (cs.uid = 86 OR es.uid = 86)
>>
>> but when c.caseid is wrapped with Count() the query will return 225:
>>
>> SELECT DISTINCT Count(c.caseid) FROM cases c LEFT JOIN casespecialty cs
>> ON c.caseid = cs.caseid LEFT JOIN examspecialty es ON c.caseid =
>> es.caseid WHERE (cs.uid = 86 OR es.uid = 86)
>>
>> The correct answer in this case is 80. I'm looking for Count() to return
>> the correct (desired) total.
>>
>>

>
> Do you want a distinct count, or a count of distinct items?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================


I'm looking the latter, a count of distinct items.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:18 AM
Philipp =?UTF-8?Q?T=C3=B6lke?=
 
Posts: n/a
Default Re: Count(*) different than record count

Bosconian <nobody@nowhere.com> schrieb:
> I'm looking the latter, a count of distinct items.


The Syntax is COUNT(DISTINCT foo)

Cheers
--
Philipp Tölke
PGP: 0x96A1FE7A
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:18 AM
Bosconian
 
Posts: n/a
Default Re: Count(*) different than record count

"Philipp Tölke" <ascii158@web.de> wrote in message
news:eg38ql$pqt$1@online.de...
> Bosconian <nobody@nowhere.com> schrieb:
>> I'm looking the latter, a count of distinct items.

>
> The Syntax is COUNT(DISTINCT foo)
>
> Cheers
> --
> Philipp Tölke
> PGP: 0x96A1FE7A


It's amazing what a difference moving one parenthesis makes. :-)

Many thanks.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:18 AM
Jerry Stuckle
 
Posts: n/a
Default Re: Count(*) different than record count

Bosconian wrote:
> "Philipp Tölke" <ascii158@web.de> wrote in message
> news:eg38ql$pqt$1@online.de...
>
>>Bosconian <nobody@nowhere.com> schrieb:
>>
>>>I'm looking the latter, a count of distinct items.

>>
>>The Syntax is COUNT(DISTINCT foo)
>>
>>Cheers
>>--
>>Philipp Tölke
>>PGP: 0x96A1FE7A

>
>
> It's amazing what a difference moving one parenthesis makes. :-)
>
> Many thanks.
>
>


Yes, you were getting a distinct count - hence my question (trying to
steer you onto the right course).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 09:18 AM
Bosconian
 
Posts: n/a
Default Re: Count(*) different than record count

"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:Y_mdnbN4ks_K0LjYnZ2dnUVZ_rmdnZ2d@comcast.com. ..
> Bosconian wrote:
>> "Philipp Tölke" <ascii158@web.de> wrote in message
>> news:eg38ql$pqt$1@online.de...
>>
>>>Bosconian <nobody@nowhere.com> schrieb:
>>>
>>>>I'm looking the latter, a count of distinct items.
>>>
>>>The Syntax is COUNT(DISTINCT foo)
>>>
>>>Cheers
>>>--
>>>Philipp Tölke
>>>PGP: 0x96A1FE7A

>>
>>
>> It's amazing what a difference moving one parenthesis makes. :-)
>>
>> Many thanks.

>
> Yes, you were getting a distinct count - hence my question (trying to
> steer you onto the right course).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================


Absolutely. Thanks for the clarification.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:49 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com