Overview of SQL

The Structured Query Language (SQL) is a language used to interact with a relational database management system. A relational database stores highlights of a data set, and is useful for performing complex queries on multiple datasets, including shot and data surveys.

SQL is a declarative computer language developed in the 1970s and standardized in the 1980s used to interact with data in a relational database. Its use is supported by all major database vendors with some minor variation between different, sometimes vendor-specific, versions of SQL. These differences may be important for some uses of SQL, but for the simple examples presented here the differences are unimportant.

The basic syntax for getting data from a table is:

SELECT columns-you-want FROM table

where columns-you-want is a comma-delimited list of columns in the table.

This will return the columns specified for all the rows in the table. It really is this simple.

An example: selecting one column

SELECT a FROM b

Another example: selecting two columns

SELECT a, b FROM c

In many cases this is all you need to know. However, you may not want to get all the rows from a table. The basic syntax for getting specified columns for some of the rows from a table is:

SELECT columns-you-want FROM table WHERE some-criteria

This will return the columns specified for those rows in the table that meet the specified criteria. The operators used in the criteria are:

 =  equal
 >  greater than
 <  less than
 >=  greater than or equal to
 <=  less than or equal to
 <>  not equal
 IS NOT NULL  true if not null
 IS NULL  true if null
 IN( a1, a2, a3, … an) in the set a1…an
 BETWEEN a AND b  between the values a and b.

A few examples:

 SELECT a FROM b WHERE a > 0
 SELECT a FROM b WHERE c > 0
 SELECT a, b FROM c WHERE d IN (1, 2)
 SELECT a FROM b WHERE a IS NOT NULL


For more information, please see

Presented with examples from the DIII-D relational database