-- This query does a table JOIN between the imaging (PhotoObj) and spectra
--(SpecObj) tables and includes the necessary columns in the SELECT to upload
--the results to the SAS(Science Archive Server) for FITS file retrieval.
SELECT
p.objid,p.ra,p.dec,s.z as redshift,
dbo.fCosmoComovDist2ObjectsRADEC(0.0,p.ra,p.dec,s.z,p.ra,p.dec,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT) as distance
FROM PhotoObj AS p
JOIN SpecObj AS s ON s.bestobjid = p.objid
WHERE s.z > 0.0
