# Very basic ADQL cheat sheet

## Examples

Use the Examples button at the bottom of this window!

Examples in the Service Provided submenu, if available,
relate to the current TAP service.

## SELECT statement:

    SELECT [TOP n] <select-list>
        FROM <table-and-join-expression>
       [WHERE <conditions>]
       [GROUP BY <column-list>]
       [HAVING <conditions>]
       [ORDER BY <column-list>]

    SELECT t.<col1> AS a, t.<col2> AS b FROM <table> AS t

    SELECT * FROM <table1> JOIN <table2> ON <expression>

## Comparison expressions

`<column> LIKE '%star%'` ('`%`' matches string, '`_`' matches single character)

    <column> = 0

    <column> IS NOT NULL

    <column> BETWEEN 0 AND 100

## Joins

    SELECT ... FROM <table1> JOIN <table2> ON <expression>

    SELECT ... FROM <table1> JOIN <table2> USING (<common-column-list>)

    SELECT ...
       FROM <table1> AS a
       JOIN <table2> AS b
       ON 1=CONTAINS( POINT('ICRS', a.ra, a.dec),
                     CIRCLE('ICRS', b.ra, b.dec, <radius-in-degrees>))

(Note: the 'ICRS' argument usually doesn't do anything, but you need it anyway)

## Upload joins

Reference TOPCAT tables as `TAP_UPLOAD.t<n>`;
table 3 in Control Window list is `TAP_UPLOAD.t3`.

Not all services support upload joins.

## More help

GAVO ADQL Cheat Sheet (PDF) (http://docs.g-vo.org/adqlref/)

GAVO ADQL Introduction (http://docs.g-vo.org/adql/)

ADQL Standard (http://www.ivoa.net/documents/latest/ADQL.html)

ADQL BNF (http://wiki.ivoa.net/internal/IVOA/IvoaVOQL/adql-bnf-v2.0.html)