Jump to content

Archived

This topic is now archived and is closed to further replies.

ViperSBT

Another Query Quandry

Recommended Posts

OK, I am trying to do the following query:
[code]SELECT d.dnumber AS RUN, SUM(p.points) AS Points FROM dogs d JOIN points p ON p.dog = d.dnumber GROUP BY d.dnumber[/code]
This returns a list of RUNs with associated Points, but it only recognizes RUNs that exist in both the dogs and points tables. I need all dogs in the dogs table regardless is they exist in the points table. If they don't exist in the points table I am expecting a null or 0 for the Points result for that RUN.

Share this post


Link to post
Share on other sites
Use a LEFT JOIN

[code]SELECT d.dnumber AS RUN, SUM(p.points) AS Points
FROM dogs d LEFT JOIN points p ON p.dog = d.dnumber
GROUP BY d.dnumber[/code]

Share this post


Link to post
Share on other sites
Dude, I couldn't feel more stupid!

Thank you, once again PHP Freaks saves the day!!!!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.