SDSS Sample SQL Queries

This page provides examples of queries against the SDSS catalogue using AstroGrid. The queries are transcribed from the SkyServer Sample SQL Queries and rewritten in ADQL format. You can type (or copy'n'paste) the query in the Query Builder window as shown in the image below.

Writing queries in ADQL (hints)

  • In the select FROM clause the format is always '<table> as t' so 'SELECT * FROM Field f' has to be written as 'SELECT * FROM Field AS f'
  • Column names must be preceded by the table name, i.e., 'SELECT u,g,r,z FROM table' does not work. You have to write 'SELECT t.u, t.g, t.r, t.i, t.z FROM table AS t' instead.
  • Tables and column names are case sensitive, write 'Field.fieldID' but not 'field.fieldid'.

Low-z QSOs using colors

Low-z QSO candidates using the color cuts from Gordon Richards. Also a simple query with a long WHERE clause.

SDSS: http://cas.sdss.org/dr5/en/help/docs/realquery.asp#lowzqso

    SELECT
        G.g, G.run, G.rerun, G.camcol, G.field, G.objID
    FROM
        Galaxy as G
    WHERE
        ( (G.g <= 22) and (G.u - G.g >= -0.27) and (G.u - G.g < 0.71) and 
          (G.g - G.r >= -0.24) and (G.g - G.r < 0.35) and (G.r - G.i >= -0.27) and 
          (G.r - G.i < 0.57) and (G.i - G.z >= -0.35) and (G.i - G.z < 0.70) )

Using three tables

Find the parameters for all objects in fields with desired PSF width and range of columns. Now we are using three tables, but it is still a simple query.

SDSS: http://cas.sdss.org/dr5/en/help/docs/realquery.asp#tables

    SELECT
        g.run, g.rerun, g.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
    FROM
        PhotoObj as p, Field asf, Segment as g
    WHERE
        f.fieldID = p.fieldID and f.segmentID = g.segmentID and g.run = 1336 and 
        g.camCol = 1 and f.field between 11 and 13 and f.psfWidth_r > 1.2 and p.colc > 400.0

Attachments