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 > problem with join want highest value record from multiple records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-10, 11:07
mac4rfree mac4rfree is offline
Registered User
 
Join Date: Jul 2009
Posts: 52
problem with join want highest value record from multiple records

Hi All,
I am facing problem in my join conditions in query. I Have two table which I want to join. Problem is for part number in table1 there are multiple values in table2 and I want to put logic on join condition which will pick the record which has max amend_date (this is one of the field of the table) in table2 for that part number.

Here is join condition in which I want to put the logic so that records with max amend date will come only.

Code:
LEFT OUTER JOIN FCFM.PO PAA ON (TRIM(PAA.I_PO_PROD_GRP)= TRIM(PO.I_PO_PROD_GRP) and PAA.I_MOD_YR = PO.I_MOD_YR and  PAA.I_PART=PO.I_PART )
left JOIN FCFM.PO_AMEND PA ON ( PA.I_MOD_YR = PAA.I_MOD_YR and  PA.I_PART=PAA.I_PART 

here i want to put that condition to get highest date records only.

 )
i tried using self join,
pa.D_PO_AMEND_ENTRD= max(pa.D_PO_AMEND_ENTRD)

but not working plz help.
Reply With Quote
  #2 (permalink)  
Old 08-10-10, 11:43
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Forget about the join for a moment and try to select only from table2 only those records whose amend_date is the latest for each part number.
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