AND mm.state = mm.state * should be AND xx.state = mm.state * or AND xx.state = tcState ; * The following query works in VFP8. I don't have VFP6 to test SELECT * FROM myTable mm ; WHERE mm.ctrl = tnCtrl ; AND mm.state = tcState ; AND NOT mm.deleted ; AND mm.version = ( ; SELECT MAX(version) ; FROM myTable xx ; WHERE xx.ctrl = mm.ctrl ; AND xx.state = mm.state ; AND xx.version <= tnVersion ) * or ... WHERE xx.ctrl = tnCtrl ; AND xx.state = tcState ; AND xx.version <= tnVersion )>Thanks for trying but this needs to run in VFP 6. I get "Error correlating fields" (I get the same error in VFP 8.) I also modified it to meet the requirement that it check only records at or below the specified version.
>SELECT * FROM myTable mm ; > WHERE mm.ctrl = tnCtrl ; > AND mm.state = tcState ; > AND NOT mm.deleted ; > AND mm.version = ( ; > SELECT MAX(version) ; > FROM myTable xx ; > WHERE xx.ctrl = mm.ctrl ; > AND xx.version <= tnVersion > AND mm.state = mm.state ) >>