For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > Re: MySQL DISTINCT SUM **SOLVED**









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: MySQL DISTINCT SUM **SOLVED**
Barand

2004-08-18, 3:57 pm

You only need LEFT JOIN when you want to pull data from a table even
though there is no matching record in the right table.

--------
sql = "SELECT stat.playerid, player.firstname,
SUM(stat.pts) as totalpts
FROM player INNER JOIN stat ON
player.playerid = stat.playerid
INNER JOIN game ON stat.gameid =
game.gameid
WHERE game.eventid = 7
GROUP BY stat.playerid,
player.firstname
ORDER BY totalpts DESC";
res = mysql_query(sql);
while (list(id, name, pts) =
mysql_fetch_row(res)) {
echo "id name
: pts<br>";
}
--------

hth

Barand

http://members.aol.com/barryaandrew...agridguide.html easy
data tables - and more

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com