
SELECT ...
       (modelMag_u-extinction_u) - 
        (modelMag_g-extinction_g)    AS umg,       
/* Einstein-de Sitter cosmology distance modulus
   (note no K-correction, no evolution correction, 
    and no internal extinction):  */
       (kPetroMag-ak) - 25 - 5*(
        LOG10(2*2.998e5*(1+z.z-SQRT(1+z.z))/75)
       ) AS M_K
FROM   lasSource             AS s, 
       lasSourceXDR7PhotoObj AS x, 
       BestDR7..PhotoObj     AS p, 
       BestDR7..SpecObj      AS z
WHERE
/* Join criteria:   */
       z.specObjID=p.specObjID    AND
       s.sourceID = x.masterObjID AND
       p.objID = x.slaveObjID     AND
       x.distanceMins IN (
       SELECT MIN(distanceMins)
       FROM   lasSourceXDR7PhotoObj
       WHERE  masterObjID = x.masterObjID AND
              distanceMins < 2.0/60.0
       ) AND ...

       
       
SELECT 
      3.6e6*COS(RADIANS(g.dec))*(g.ra-T2.ra)/((mj.mjdObs - T2.jdate+2400000.5)/365.25) AS pmRA, 
      3.6e6*(g.dec-T2.dec)/((mj.mjdObs - T2.jdate+2400000.5)/365.25)                   AS pmDEC
FROM 
      gcsMergeLog AS l, Multiframe AS mj, (
         SELECT t.ra AS ra, t.dec AS dec, x.slaveObjID AS slaveObjID,
                x.masterObjID AS masterObjID, t.j_m, t.h_m, t.k_m, t.jdate
         FROM   gcsSourceXtwomass_psc AS x, TWOMASS..twomass_psc AS t
         WHERE  x.slaveObjID=t.pts_key AND distanceMins IN (
            SELECT MIN(distanceMins) FROM gcsSourceXtwomass_psc WHERE masterObjID=x.masterObjID
         )
      ) AS T2 RIGHT OUTER JOIN gcsSource AS g ON (g.sourceID=T2.masterObjID)
WHERE 
      g.frameSetID=l.frameSetID AND
      l.jmfID=mj.multiframeID AND ...

       
       
       
       
SELECT ra,dec
FROM   lasMergeLog
WHERE  j_1mfID > 0 AND
       hmfID   > 0 AND
       kmfID   > 0
/* UKIDSS DR2 rows returned: 6,242
   Execution time:           00m 04s  */


-- Infrared colour-selected sources that are optical drop-outs - U1

SELECT COUNT(*)
FROM   lasSource
WHERE
/* Colour cuts for mid-T & later: */
       ymj_1Pnt > 0.5 AND
       j_1mhPnt < 0.0 AND
/* Source not detected above 2sigma within  
   1" in SDSS-DR5 i' or z':                */
       sourceID NOT IN (
       SELECT masterObjID
       FROM   lasSourceXDR5PhotoObj AS x,
              BestDR5..PhotoObj     AS p
       WHERE  p.objID = x.slaveObjID   AND
              (psfMagErr_i < 0.5       OR 
               psfMagErr_z < 0.5)      AND
              x.distanceMins < 1.0/60.0
        ) AND
/* Use only frame sets overlapping with 
   SDSS-DR5:                            */
       frameSetID IN (
       SELECT DISTINCT(frameSetID)
       FROM   lasSource             AS s,
              lasSourceXDR5PhotoObj AS x
       WHERE  s.sourceID = x.masterObjID
       ) AND
/* Unduplicated or primary duplicates only: */
        (priOrSec = 0 OR priOrSec = frameSetID) AND
/* Generally good quality: */
        yppErrBits   < 256 AND
        j_1ppErrBits < 256 AND
        hppErrBits   < 256 AND
/* Point-like morphological classification: */
        mergedClass=-1 AND
        mergedClassStat BETWEEN -3.0 AND +3.0 AND
/* Reasonably circular images in YJH: */
        yEll   < 0.35 AND 
        j_1Ell < 0.35 AND 
        hEll   < 0.35 AND
/* IR pairs within 0.5 arcsec: */
        j_1Xi  BETWEEN -0.5 AND +0.5 AND
        j_1Eta BETWEEN -0.5 AND +0.5 AND
        hXi    BETWEEN -0.5 AND +0.5 AND
        hEta   BETWEEN -0.5 AND +0.5 AND
/* YJ measured to 5 sigma and H to 4sigma: */
        yAperMag3Err   < 0.20 AND
        j_1AperMag3Err < 0.20 AND
        hAperMag3Err   < 0.25
/* UKIDSS DR2 rows returned: 1 (count=25)
   Execution time:           00m 48s  */

