-- Find quasars with a broad absorption line and a nearby galaxy. 
-- within 10 arcseconds. 
-- Return both the quasars and the galaxies.      
--
--This Sample Query will not work for SDSS3 DR8 contexts

   SELECT Q.BestObjID as Quasar_candidate_ID , G.ObjID as Galaxy_ID, N.distance
   FROM SpecObj       	as Q, 		-- Q is the specObj of the quasar candidate
        Neighbors       as N,		-- N is the Neighbors list of Q
	Galaxy          as G,		-- G is the nearby galaxy
        SpecClass  	as SC,		-- Spec Class
        SpecLine        as L, 		-- L is the broad line we are looking for 
   	SpecLineNames   as LN 		-- Line Name
  WHERE Q.SpecClass =SC.value	  	-- Q is a QSO
    and SC.name  in ('QSO', 'HIZ_QSO') 	-- Spectrum says "QSO"
    and Q.SpecObjID = L.SpecObjID	-- L is a spectral line of Q.
    and L.LineID = LN.value		-- line found and  
    and LN.Name != 'UNKNOWN' 		--      not not identified
    and L.ew < -10			-- but its a prominent absorption line
    and Q.BestObjID = N.ObjID		-- N is a neighbor record
    and G.ObjID = N.NeighborObjID  	-- G is a neighbor of Q
    and N.distance < 10.0/60	-- and it is within 10 arcseconds of the Q. 
