dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Mysql + Join + Count! - mysql

This is a discussion on Mysql + Join + Count! - mysql ; Well basically, the COUNT function returns faulty results... when I echo uptime_votes & package_votes they both output the number 10. package_ratings has 5 records uptime_ratings has 2 records ... 5 X 2 = 10 and yes, when I add another ...


Home > Database Forum > Other Databases > mysql > Mysql + Join + Count!

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 04-28-2009, 03:09 PM
Database Newbie
 
Join Date: Apr 2009
Posts: 1
Contagious is on a distinguished road
Default Mysql + Join + Count!

Well basically, the COUNT function returns faulty results... when I echo
uptime_votes & package_votes they both output the number 10.

package_ratings has 5 records
uptime_ratings has 2 records ...

5 X 2 = 10 and yes, when I add another record in uptime_ratings the result outputs 15 ! what the heck is going on
PHP Code:
<?php
$sQuery 
=
"
SELECT
    hosts.id AS iD,
    DATE_FORMAT(hosts.date_added,'%Y-%m-%d' ) AS added,
    DATE_FORMAT(hosts.date_updated,'%Y-%m-%d' ) AS updated,
    hosts.name,
   
    package_main.freehost_id,
    package_main.diskstorage,
    package_main.bandwidth,
    package_main.forcedads,
   
    package_ratings.freehost_id,
    uptime_ratings.freehost_id,
    overall_ratings.freehost_id,
    COUNT(uptime_ratings.freehost_id) AS uptime_votes
    COUNT(package_ratings.freehost_id) AS package_votes
   
   
   
   
   
   
   
   
   
   
   


FROM hosts
   
LEFT JOIN package_main ON hosts.id = package_main.freehost_id
LEFT JOIN package_ratings ON hosts.id = package_ratings.freehost_id
LEFT JOIN uptime_ratings ON     hosts.id = uptime_ratings.freehost_id
LEFT JOIN overall_ratings ON hosts.id = overall_ratings.freehost_id



GROUP BY   
    hosts.id,
    hosts.date_added,
    hosts.date_updated,
    hosts.name,
    package_main.freehost_id,
    package_main.diskstorage,
    package_main.bandwidth,
    package_main.forcedads,
    package_ratings.freehost_id,
    uptime_ratings.freehost_id,
    overall_ratings.freehost_id
   
   
ORDER BY

    date_added DESC LIMIT "
.$aNavigatie['iVanaf'].", ".$iMaxPerPagina


;
?>
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 12:53 PM.