-- Diameter-limited sample of galaxies 
-- from James Annis.
-- Another query that makes extensive use of photo flags to get a sample
-- of galaxies within a size range as specified by their i-band Petrosian
-- radius.

SELECT TOP 100
  run,
  camCol,
  rerun,
  field,
  objID,
  ra, 
  dec
FROM Galaxy
WHERE ( flags & (dbo.fPhotoFlags('BINNED1')
                + dbo.fPhotoFlags('BINNED2')
                + dbo.fPhotoFlags('BINNED4')) ) > 0 
  and ( flags & (dbo.fPhotoFlags('BLENDED')
                + dbo.fPhotoFlags('NODEBLEND')
                + dbo.fPhotoFlags('CHILD')) ) != dbo.fPhotoFlags('BLENDED')
  and ( ( (flags & dbo.fPhotoFlags('NOPETRO') = 0)
      and  petrorad_i > 15)
    or  ( (flags & dbo.fPhotoFlags('NOPETRO') > 0)
      and petrorad_i > 7.5)
    or  ( (flags & dbo.fPhotoFlags('TOO_LARGE') > 0)          
      and  petrorad_i > 2.5)
    or 
        ( (flags & dbo.fPhotoFlags('SATURATED') = 0)           
      and  petrorad_i > 17.5) )
