If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > COUNT times 2!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-09, 14:07
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
COUNT times 2!

The following query is doubling the count of "cases" in the patients table. The "doc" in the members table has only one case but the query is reporting 2!


Thanks

Oldnickj

SELECT members.mfirst , members.mmiddle , members.mlast , members.id , members.member_id , label.descr_lbl , EXTRACT(YEAR
FROM patients.cdate) AS Year , EXTRACT(MONTH FROM patients.cdate) AS yyyymm , COUNT(patients.doc_id)
FROM members
INNER
JOIN label ON label.value_lbl = members.demo5
INNER JOIN patients ON patients.doc_id = members.id AND members.mlast ='jewett'
GROUP BY members.id , yyyymm
ORDER BY mlast, patients.cdate
Reply With Quote
  #2 (permalink)  
Old 12-02-09, 14:59
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Count 2

I should add that we have about 35k records which is slowing things a bit.

Nick
Reply With Quote
  #3 (permalink)  
Old 12-02-09, 17:51
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Count2

Then the next question is what can I do to optimize the tables or the query?

Oldnickj
Reply With Quote
  #4 (permalink)  
Old 12-03-09, 09:35
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Count 2

The solution I received was that I had two "labels" with the same value. Thank God for forums!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On