If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 19:48
xianwinwin xianwinwin is offline
Registered User
 
Join Date: Jun 2006
Location: NY
Posts: 14
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, 07:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-09-07, 10:18
xianwinwin xianwinwin is offline
Registered User
 
Join Date: Jun 2006
Location: NY
Posts: 14
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

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