-- Objects selected by cuts on three tables.
-- Find the parameters for all objects in a selected field with
-- desired PSF width and range of columns.
-- Now we are using three tables, but it is still a simple query.

SELECT TOP 1000
   f.run,
   f.rerun,
   f.camCol,
   f.field,
   p.objID,
   p.ra,
   p.dec,
   p.Rowc,
   p.Colc,
   p.u,
   p.modelMagErr_u ,
   p.g,
   p.modelMagErr_g,
   p.r,
   p.modelMagErr_r,
   p.petroMag_r - p.extinction_r,
   p.petroMagErr_r,
   p.i,
   p.modelMagErr_i,
   p.z,
   f.psfWidth_r,
   r.stripe,
   r.strip
FROM
   photoObj p
   JOIN field f ON f.fieldid = p.fieldid
   JOIN run r ON r.run=f.run
WHERE
  f.psfWidth_r > 1.2
  and  p.colc > 400.0
