How to find the distance between two galaxies from ra and dec and redshift I have ra and dec and corresponding redshift of galaxies. I would like to calculate the distance between two galaxies.
I did like this to find the nearest neighbour galaxies.
Suppose I am trying to find the nearest neighbour of galaxy A(which has RA,DEC)  and the target galaxy has ra1,dec1,
so to find the distance between two galaxy, I did like this
dist_sqd= sqrt( (RA-ra1)**2 + (DEC-dec1)**2 ) 
#RA, DEC are in degree

Is this the correct way to find the distance.
As there is projection in 2D, Since, I already have redshift, Is there any best way to find the distance between two galaxies properly?
Since you are presumably using Hubble's law to get the distance to each of the galaxies, the approximate estimate would the &quot;the greater distance ± the smaller distance&quot;.
But the geometric solution is useful too. Your strategy appears to be something like:

Calculate angular separation $\Theta$ from RA and DEC.
By trigonometry, the distance is then $d_{a,b} = \sqrt{d_a^2\sin(\Theta)^2 + (d_b - d_a\cos(\Theta))^2}$

The problem is that you can not calculate the angular separation on a sphere by the Pythagorean formula, instead, you need the haversine formula. To keep this post self-contained, that is:
$$\Theta = 2\sin^{-1}\left(\sqrt{\sin^2\left(\frac{\phi_2 - \phi_1}{2}\right) + \cos(\phi_1)\cos(\phi_2)\sin^2\left(\frac{\lambda_2 - \lambda_1}{2}\right)}\right)$$
Where $\phi$ is declination and $\lambda$ is right ascension.
People are also linking this answer from the comments, which deals with the problem by converting everything to Cartesian coordinates first, which may or may not be easier for your use case.