On 1 Mar 2011, at 22:01, Jeff Archer wrote: > Hi all, and thanks in advance for you help. > > And this select which I would like to modify to only return lowest X,Y value > for each ImageID. > > select Defects.DefectID > , Defects.ImageID > , Defects.AnalysisID > , Defects.X > , Defects.Y > , Defects.W > , Defects.H > , Defects.Area > , Images.X + Defects.X as DefectX > , Images.Y + Defects.Y as DefectY > from Defects join Images on Defects.ImageID = Images.ImageID
…ORDER BY DefectX * DefectX + DefectY * DefectY ASC LIMIT 1; More generally, the nearest to a target point (Tx,Ty) is: …ORDER BY (DefectX-Tx)*(DefectX-Tx) + (DefectY-Ty)*(DefectY-Ty) ASC LIMIT 1; Since more than one distinct point can be at the same distance from the target, these queries cannot guarantee the same result if executed twice on the same data. Best Regards, Phil Willoughby -- Managing Director, StrawberryCat Limited StrawberryCat Limited is registered in England and Wales with Company No. 7234809. The registered office address of StrawberryCat Limited is: 107 Morgan Le Fay Drive Eastleigh SO53 4JH _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users