SELECT primary.primary_id, primary.initiated, primary.completed, 
SUM(secondary.received)
FROM primary LEFT OUTER JOIN secondary 
ON primary.primary_id = secondary.primary_id
GROUP BY primary.primary_id, primary.initiated, primary.completed

+-----------------------------------------------+
Bryan Love
  Macromedia Certified Professional
  Internet Application Developer
  Database Analyst
Telecommunication Systems
[EMAIL PROTECTED]
+-----------------------------------------------+

"...'If there must be trouble, let it be in my day, that my child may 
have
peace'..."
        - Thomas Paine, The American Crisis



-----Original Message-----
From: stas [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 08, 2003 8:52 AM
To: CF-Talk
Subject: Re: I need to do a sum on a secondary (left outer join)
table...


Use ISNULL()

SELECT ..., SUM(ISNULL(secondary.received,0))
.

This will assign 0 to any rows that don't have a value in that column.

Or don't use an OUTER JOIN :D


----- Original Message ----- 
From: "Tyler Silcox" <[EMAIL PROTECTED]>



Is there a way to grab all the records from one table and sum up all 
the 
values of a column from another table based on a foreign key?

This is what I'm trying to do:

SELECT primary.primary_id, primary.initiated, primary.completed, 
SUM(secondary.received)
FROM primary LEFT OUTER JOIN secondary 
ON primary.primary_id = secondary.primary_id



______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to