I have a table: points
it has 2 filds: X, Y
each row represents a dot on 2d field
I want to be capable of performing search of dots with in some radius R like

and is square with side A like

BTW: I use PHP to access my DB.
My main point is to get nearest to center of figure point as first result in the quqe like

How to do such thing in SQL?