Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > how come the result is not in this list? (it works fine when I pinpoint to it)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-08-07, 20:48
xianwinwin xianwinwin is offline
Registered User
 
Join Date: Jun 2006
Location: NY
Posts: 13
how come the result is not in this list? (it works fine when I pinpoint to it)

Hi there,
I've been trying to understand this problem for a while - no luck!
assistance would highly appropriated.

here's the deal:

I have this query:

SELECT D.debit_id, D.date, D.status_2, D.GOF, TA.legal_name, TA.taid, TAP.totalPay, TD.totalDebit AS amountDue
FROM TomasAar AS TA, debit AS D

LEFT JOIN (SELECT SUM( Amount ) AS totalPay, debit_id
FROM ta_payments
GROUP BY debit_id ) AS TAP ON ( TAP.debit_id = D.debit_id )

LEFT JOIN ( SELECT SUM( debit_amount ) AS totalDebit, debit_id
FROM transaction_debit
WHERE transaction_status =0
GROUP BY debit_id) AS TD ON ( TD.debit_id = D.debit_id )

WHERE D.GOF= TA.GOF
AND D.status_2 =5
AND D.GOF=10001
GROUP BY TD.debit_id
ORDER BY TA.GOF

this return the following result:

94....2007-06-15.....10001....Peterson....993...null....nulll

when I remove the line: AND D.GOF=10001
I get a list where 10001 is not in it...WHY???

* initially I though it's becuase of the null...nulll - but the list has some values of null...null

thanks for any pointers
Reply With Quote
  #2 (permalink)  
Old 10-09-07, 08:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,556
Quote:
Originally Posted by xianwinwin
when I remove the line: AND D.GOF=10001
I get a list where 10001 is not in it...WHY???
because you took out that line, that's why

tip: never mix comma-delimited table syntax with JOIN syntax

here is how i would write your query:
Code:
SELECT D.debit_id , D.date , D.status_2 , D.GOF , TA.legal_name , TA.taid , TAP.totalPay , TD.totalDebit AS amountDue FROM TomasAar AS TA INNER JOIN debit AS D ON D.GOF = TA.GOF AND D.status_2 = 5 AND D.GOF = 10001 LEFT OUTER JOIN ( SELECT SUM( Amount ) AS totalPay , debit_id FROM ta_payments GROUP BY debit_id ) AS TAP ON TAP.debit_id = D.debit_id LEFT OUTER JOIN ( SELECT SUM( debit_amount ) AS totalDebit , debit_id FROM transaction_debit WHERE transaction_status =0 GROUP BY debit_id ) AS TD ON TD.debit_id = D.debit_id ORDER BY TA.GOF
notice anything else? no GROUP BY!
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 10-09-07, 11:18
xianwinwin xianwinwin is offline
Registered User
 
Join Date: Jun 2006
Location: NY
Posts: 13
Wow....thank You Thank You Thank You!!!!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On