Ask a Question related to Coldfusion Database Access, Design and Development.
-
jhilty #1
three table outer join with aggregate functions
here is a query joining three tables (SQL 2000) that doesn't return the results
i need.
SELECT o.OutID, o.GroupID, o.OutTitle, o.SubHead, o.OutOrder,
COUNT(q.QuestionID) AS NumQuestions,
COUNT(f.FlashCardID) AS NumCards
FROM Outline o
LEFT OUTER JOIN Questions q ON q.OutID = o.OutID
LEFT OUTER JOIN Flashcards f ON f.OutID = o.OutID
WHERE o.GroupID = #URL.GroupID#
GROUP BY o.OutID, o.GroupID, o.OutTitle, o.SubHead, o.OutOrder
ORDER BY o.OutOrder
In theory this should give me the info from the Outline table and then count
up the total number of questions and flashcards that are associated with each
Outline item (if any)
I don't get any errors, but the results are not correct for the count's. If
there are 2 questions and 3 flashcards for a given Outline item, both the
NumQuestions and NumCards variable return a 6.
works fine if I only work with one of the tables (Questions or Flashcards) but
not when I try to combine both at once.
I'm stumped - any ideas?
jhilty Guest
-
Outer join?
Sometimes I need to make queries and join tables, knowing that the other table rows are not always available. Example: I do SELECT... -
Left Outer Join
Hi, I have noticed when I do a Left Outer Join in short form that many rows become missing as result of null values. i.e Left Outer Join... -
OUTER JOIN
I can't get this outer join to work, It worked when i made it into a inner join Select * FROM dbo.tEmployee OUTER JOIN dbo.tEmployeeaccess ON... -
FULL OUTER JOIN
Will Cold Fusion process a FULL OUTER JOIN in a cfquery? -
SQL query with a Left outer Join
I have a problem with this query. I have a left outer join with a table OrderStatus but, I don't want it to reterive those records where the field... -
jhilty #2
Re: three table outer join with aggregate functions
so here's one solution - adding DISTINT to the count aggregate functions seems to work
COUNT(DISTINCT(q.QuestionID)) AS NumQuestions,
COUNT(DISTINCT(f.FlashCardID)) AS NumCards
jhilty Guest
-
Unregistered #3
Re: three table outer join with aggregate functions
Thank you very much! I've been trying to solve this similar problem with no luck for the past 2 days!
Now I can finally move on with my project balance sheet!Unregistered Guest



Reply With Quote

