I have 2 tables that I need to extract data from, say PORTS and STATS.
PORTS contains a list of Sea Ports in PORT i.e. : -
STATS contains a few thousand records that with among other things has the elements
TO_PORT and AMOUNT.
the entries in TO_PORT match the ports in PORT.
Now one of the things I want to do is produce a summary of the totals of AMOUNT
against the ports in PORTS, including (and this is the important bit that I'm stuck
on) the ports in PORTS that do not have a match in STATS.TO_PORT. so that I get a
result such as : -
and NOT :-
Which is all I can get at the moment.
the query I am using is : -
SELECT PORTS.PORT, SUM(STATS.AMOUNT) FROM PORTS LEFT JOIN STATS ON PORTS.PORT =
STATS.TO_PORT GROUP BY PORTS.PORT
Basicaly what I want to do is pull out a list of all entries in PORTS.PORT and put a
total figure against it from STATS.AMOUNT where the STATS.TO_PORT matches PORTS.PORT
and just a zero if theres no entry in STATS.
Anyone got any ideas?
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php