-- Find galaxies with specific spectra.
-- Namely, they have an equivalent width in
-- H_alpha > 40 Angstroms. We want object ID's from the photometry (Galaxy)
-- but constraints from spectroscopy. The line widths and IDs are stored in
-- SpecLine.  --This is a simple query, but now we are using three tables. The
-- spectroscopy tables of measured lines are arranged non-intuitively, and we
-- urge users to read about them on the DAS help pages.  --IMPorTANT NOTE:
-- Each spectroscopic object now has a match to at least two photometric
-- objects, one in Target and one in Best. Therefore, when performing a join
-- between spectroscopic photometric objects, you must specify either
-- PhotoObj.ObjID=SpecObj.bestObjID or PhotoObj.ObjID = SpecObj.targetObjID.
-- Normally, the default photometric database is BEST, so you will want to use
-- SpecObj.bestObjID

SELECT G.ObjID  -- we want the photometric ObjID
FROM Galaxy as G,   -- G is the galaxy
  SpecObj   as S,   -- S is the spectra of galaxy G
  SpecLine  as L,    -- L is a line of S
  SpecLineNames as LN  -- the names of the lines

WHERE G.ObjID = S.bestObjID	-- connect the galaxy to the spectrum
     and S.SpecObjID = L.SpecObjID   -- and the spectral line L is detected in the spectrum
     and L.LineId = LN.value		-- L is the H alpha line
     and LN.name =  'Ha_6565'   
     and L.ew > 40                   -- and H alpha is at least 40 angstroms wide.
