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 > DB2 > Complex query left join

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-06, 15:46
mara_anda mara_anda is offline
Registered User
 
Join Date: Jul 2004
Posts: 7
Complex query left join

Hi,

I have this query in Sybase which need to be migrated on DB2.

How will be in DB2 this query ? Please help!
SELECT
a.*
FROM
( SELECT o.business, o.br as br ,o.ord as ord, d.trde as trde
FROM table e, table tf, table o, table d,

WHERE o.business = '2006-01-04'
AND o.source = '7'
AND e.exec *= tf.exec
AND e.exec *= tf.exec
AND e.as *= tf.as
AND o.ord *= e.ord
AND o.ord *= e.ord
AND o.ord *= e.ord
AND o.acct *= d.acct
AND o.acct_no *= d.acct_no

) a, table bd, table bdt
WHERE a.br *= bd.br
AND a.ord *= bdt.bra
AND (a.trde not in ('a','x','w') OR a.trde is null)
;

Thanks.
Reply With Quote
  #2 (permalink)  
Old 01-16-06, 03:07
gardenman gardenman is offline
Registered User
 
Join Date: Apr 2004
Posts: 54
use LEFT OUTER JOIN instead of *=
Reply With Quote
  #3 (permalink)  
Old 01-16-06, 10:49
mara_anda mara_anda is offline
Registered User
 
Join Date: Jul 2004
Posts: 7
mara

Can you please send me the query using left join ?

Thanks.
Reply With Quote
  #4 (permalink)  
Old 01-17-06, 11:09
ihendr ihendr is offline
Registered User
 
Join Date: Mar 2005
Posts: 7
should be something like

select ...
from (...) a
left outer join bd on a.br=bd.br
left outer join bdt on a.ord=bdt.bra
where (a.trde not in ('a','x','w') OR a.trde is null)
Reply With Quote
  #5 (permalink)  
Old 01-17-06, 11:40
mara_anda mara_anda is offline
Registered User
 
Join Date: Jul 2004
Posts: 7
complex query

Hi,
Thank you for your answer.

Here is the issue


where (a.trde not in ('a','x','w') OR a.trde is null)

Because trde is a column from an unpreserved table the condition is not correct. If this query is ran it on Sybase and DB2 the result set is different.

So, which can be the solution ?
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