Question

Asked:
Asked By:
Jan 9 2009   4:46 PM GMT
ThorButtox   5 pts.

DB2 SQL Confusion


DB2 SQL, SQL, DB2

I am failing to understand why the following won't work

SELECT m.index, SUM(d1.amt), SUM(d2.amt)
FROM master m,
detail d1,
detail d2
WHERE m.index = d1.index
AND m.index = d2.index
AND d2.qalif = 1
GROUP BY m.index

I wrote another sql that does work, I just don't understand why I get higher values on SUM(d2.amt) than I am expecting.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



To be able to help, I think we would need to know your table structures, and see what results are you getting and what results are you expecting with some example data.

When joining tables, if you do not write the appropriate join conditions, you could be duplicating rows.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and DataManagement.

Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register