Jump to content


Photo

Another Query Quandry


  • Please log in to reply
2 replies to this topic

#1 ViperSBT

ViperSBT
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 09 May 2006 - 01:40 PM

OK, I am trying to do the following query:
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
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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,167 posts

Posted 09 May 2006 - 11:22 PM

Use a LEFT JOIN

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 ViperSBT

ViperSBT
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 10 May 2006 - 02:05 AM

Dude, I couldn't feel more stupid!

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users