I have 3 tables, j1,j2,j3. In j1 I have the jobs, and in j2,j3 the moves. For each job there are several moves. I write
SELECT
j1.JNumber,
j3.MNumber,
j3.ADate,
other fields….
FROM j1 WITH(READUNCOMMITTED)
inner join j2 WITH(READUNCOMMITTED)
on j1.JNumber=j2.JNumber
inner join j3 WITH(READUNCOMMITTED)
on j2.MNumber=j3.MNumber
Please help me, if it's possible, to write a select statement or a script, or a stored procedure, that retrieves one record for each job with the mov in which ADate is the maximum.
So, for example, instead of
j60 ma60 01/01/2010
j60 mb60 27/01/2010
j62 mc62 01/01/2010
j62 md62 29/01/2010
j87 me87 05/02/2010
j87 mf87 12/01/2010
I have to have
j60 mb60 27/01/2010
j62 md62 29/01/2010
j87 me87 05/02/2010
Thanks
SELECT
j1.JNumber,
j3.MNumber,
j3.ADate,
other fields….
FROM j1 WITH(READUNCOMMITTED)
inner join j2 WITH(READUNCOMMITTED)
on j1.JNumber=j2.JNumber
inner join j3 WITH(READUNCOMMITTED)
on j2.MNumber=j3.MNumber
Please help me, if it's possible, to write a select statement or a script, or a stored procedure, that retrieves one record for each job with the mov in which ADate is the maximum.
So, for example, instead of
j60 ma60 01/01/2010
j60 mb60 27/01/2010
j62 mc62 01/01/2010
j62 md62 29/01/2010
j87 me87 05/02/2010
j87 mf87 12/01/2010
I have to have
j60 mb60 27/01/2010
j62 md62 29/01/2010
j87 me87 05/02/2010
Thanks