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 > conversion from oracle to DB2 syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-09, 22:51
maxzsim maxzsim is offline
Registered User
 
Join Date: May 2009
Posts: 4
conversion from oracle to DB2 syntax

Hi,

I have the following SQL written in Oracle :

SELECT DISTINCT A.* FROM MyTABLEA A , MyTABLEB B
WHERE A.ID = '77787'
AND A.ID =B.ID(+)
AND A.MAIN = B.MAIN(+)
AND A.NO = B.NO(+)
AND A.EQP = B.EQP(+)
AND A.JOB_ID = B.JOB_ID(+)

my purpose is to get all record fro ID =7787 from MYTABLEA even if no matching record in MYTABLEB

i tried

SELECT DISTINCT A.* FROM MyTABLEA A LEFT OUTER JOIN MyTABLEB B
ON A.ID = '77787'
AND A.ID =B.ID
AND A.MAIN = B.MAIN
AND A.NO = B.NO
AND A.EQP = B.EQP
AND A.JOB_ID = B.JOB_ID

but it seems to return ALL records from MyTABLEA and not just limited to the specified records from MYTABLEA

please advise
Reply With Quote
  #2 (permalink)  
Old 05-29-09, 01:33
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You need to find a SQL manual on how to do an outer join. You must separate the join predicates (ON) from the predicates you want to filter the rows (WHERE) in the first table.

So it looks to me like A.ID = '77787' should be in a WHERE clause of the outer join, and not used in the ON clause.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 05-29-09, 13:27
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
As Marcus says above you are not limiting what you want from the A table. You are only limiting when you perform the outer join to the B table, so that the only time you will see data that exists in the B table is when the A.ID is '77787'.

Dave
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