> > Hi SQL experts (I hope),
> >
[quoted text clipped - 45 lines]
> Regards,
> Kristian
Hi Kristian,
Thx for the swift response!
The answer is _yes_ they're independent. (The 2nd option isn't
sufficient then.)
It'll probably help to show the real situation:
Contract_Nr Version Status_Sort* Status
1100141145 1 3 arc
1100141145 1 3 can
1100142899 1 1 act
1100243970 3 1 act
1100243970 1 3 can
1100243970 2 3 wfa
Note: Status_Sort is generated thru a "Case when", and creates a value
based on a series of statuses, e.g. "either WFA or UC result in 2" and
"CAN or ARC result in 3", therefore they can appear more than once.
I only want the (contract_nr, version) returned of which the status is
lowest, i.e.
1100141145,1
1100243970,3
etc.
Thanks once again,
Armando
Kristian Damm Jensen - 30 Sep 2004 11:48 GMT
<snip>
> It'll probably help to show the real situation:
>
[quoted text clipped - 15 lines]
> 1100243970,3
> etc.
But then the solution is even simpler
select contract_nr, min(version)
from Tab
group by contract_nr
Regards,
Kristian
Tokunaga T. - 30 Sep 2004 16:13 GMT
> It'll probably help to show the real situation:
>
[quoted text clipped - 15 lines]
> 1100243970,3
> etc.
How about this?
SELECT t1.Contract_Nr
, t1.Version
FROM Contract_Status t1
, Contract_Status t2
WHERE t2.Contract_Nr = t1.Contract_Nr
GROUP BY
t1.Contract_Nr, t1.Status, t1.Version
HAVING
MIN(t2.Status) = t1.Status
;