Author |
Topic |
domo
Starting Member
23 Posts |
Posted - 2008-04-10 : 08:12:37
|
Here's a data sample:mrID, mrSEQUENCE, mrFIELDNAME, mrNEWFIELDVALUE, mrOLDFIELDVALUE, mrUSERID1867, 3244, mrSTATUS, Request, NULL, DH43781867, 3245, mrSTATUS, Open, Request, HD90341867, 3705, mrSTATUS, Closed, Open, DH43781867, 3246, mrSTATUS, Reopened, Closed, DH43781868, 3249, mrSTATUS, Request, NULL, DL48481868, 3250, mrSTATUS, Open, Request, DL48481870, 3255, mrSTATUS, Closed, Open, DL4848I need to output all instances where mrNEWFIELDNAME = 'Closed' AND its the last in mrSEQUENCE.mrID 1867 fails to meet the criteria as the last new value added is 'ReOpened'. 1870 Qualifies as the last new value added is 'Closed'.The query should return the the output as if viewing the table, only showing one instance of mrID.The results if run against the sample above would be:1870, 3255, mrSTATUS, Closed, Open, DL4848Your help would be happily received  |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 08:18:03
|
What defines the order of records in the table? E 12°55'05.25"N 56°04'39.16" |
 |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-04-10 : 08:32:58
|
To me both 1867 and 1870 qualify as desired records since both of your criterias are satisfied. If not, then your mrSEQUENCE is out of sequence.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-10 : 13:07:53
|
[code]SELECT t1.mrID, t1.mrSEQUENCE, t1.mrFIELDNAME, t1.mrNEWFIELDVALUE, t1.mrOLDFIELDVALUE, t1.mrUSERIDFROM YourTable t1INNER JOIN (SELECT mrID,MAX(mrSEQUENCE) AS MaxSequence FROM YourTable GROUP BY mrID)t2ON t2.mrID=t1.mrIDAND t2.MaxSequence=t1.mrSEQUENCEWHERE t1.mrNEWFIELDVALUE='Closed'[/code]EDIT:Added aliases in SELECT list |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-10 : 14:45:26
|
Visakh, if you read OP carefully, you can see that the mrSEQUENCE do not apply for "last" record. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|