Hi All,
I have a simple table that I need to extract some records from...
And what I need is...
What I'm trying is to extract the most recent record for each drawing and where there are two on the same date, take the one with the biggest drgno.
I ought to be able to do this with a subquery, but I can't work it out. I tried using a 'TOP 1', 'ORDER BY' subquery but the OLEDB I'm using doesn't support that for correlated subqueries. I tried using max() but I need the max of two fields and I just can't get my head around it.
Any help would be gratefully received.
Martin
This is the closest I have got:
CODE
SELECT * FROM myTable a WHERE drgno in (SELECT MAX(drgno) from myTable b WHERE a.madeby=b.madeby AND a.clientdrg=b.clientdrg) ORDER BY madeby,clientdrg
But it ignores the daterecd bit
Regards
Griff
Keep ing
Regards
Griff
Keep [Smile]ing
I have a simple table that I need to extract some records from...
Code:
madeby clientdrg daterecd drgno
A 1234 20080101 800
A 1234 20080102 810
A 1234 20080103 808
A 1234 20080103 809
A 5678 20080101 799
A 5678 20080102 904
A 5678 20080104 989
A 5678 20080105 905
A 5678 20080105 915
And what I need is...
Code:
madeby clientdrg daterecd drgno
A 1234 20080103 809
A 5678 20080105 915
What I'm trying is to extract the most recent record for each drawing and where there are two on the same date, take the one with the biggest drgno.
I ought to be able to do this with a subquery, but I can't work it out. I tried using a 'TOP 1', 'ORDER BY' subquery but the OLEDB I'm using doesn't support that for correlated subqueries. I tried using max() but I need the max of two fields and I just can't get my head around it.
Any help would be gratefully received.
Martin
This is the closest I have got:
CODE
SELECT * FROM myTable a WHERE drgno in (SELECT MAX(drgno) from myTable b WHERE a.madeby=b.madeby AND a.clientdrg=b.clientdrg) ORDER BY madeby,clientdrg
But it ignores the daterecd bit
Regards
Griff
Keep ing
Regards
Griff
Keep [Smile]ing