Reply to topic
Coldfusion and SQL
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
I have this query on MS SQL 2005

Code:

SELECT tbl_category.catname, sum(tbl_answered_questions.points) as points
FROM tbl_answered_questions, tbl_question, tbl_category
WHERE tbl_answered_questions.qid = tbl_question.qid
AND tbl_question.catid = tbl_category.catid
AND tbl_answered_questions.uid = 2
GROUP BY tbl_category.catname


on the MS SQL Management Studio works fine, but when I try to display on the cfoutput I get the wrong output. I get 4

but since I group I should get
Group 1: 0
Group 2: 2
Group 3: 2

Here is my output

Code:

<cfoutput query="qryGetPoints">
<tr>
     <td width="14%" height="10" class="myaccount2">#points#</td>
     <td width="86%" height="10" class="myaccount3"></td>
</tr>
</cfoutput>
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1029
Location: Felton, Delaware
Reply with quote
Why don't you try using a proper join?

Code:
SELECT category.catname, sum(answer.points) AS points
FROM tbl_answered_questions AS answer
INNER JOIN tbl_question AS question ON tbl_answered_questions.qid = tbl_question.qid
INNER JOIN tbl_category AS category ON tbl_answered_questions.catid = tbl_category.catid
WHERE tbl_answered_questions.uid = 2
GROUP BY category.catname
ASC


Or something like that?
Coldfusion and SQL
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic