As seen in the previous example, a basic SQL query block syntax is something like:

We will add more complexity, but for now this is the basic setup. Consider the following table, containing these columns:

An Instruments table, 
           with columns for instrument_id as primary key, instrument_model and last_maintenance_date
An instruments table, with columns for instrument_id as primary key, instrument_model and last_maintenance_date
This is a table of specific instruments, with a unique identifier for each instrument and a record of the instrument_model and the last date this particular instrument was maintained. Say, for example, we would like all of the data in the table:
This then returns all of the data in the table:
All of the data in the
        Instruments table
All of the data in the Instruments table, returned by the query

As an aside, as mentioned in the topic designing databases, as instrument_id is a surrogate key it is like that the full table would also include a field for a real-world identifier such as a serial number. In addition, as in this case we only query one table and our scope is restricted to that, there is no room for ambiguity in column names and we could have omitted the aliased table name and qualified column names; it is often good practice to always include them, however, particularly as it's common for a query to become the base of a larger query which may include more tables.

If we are requesting the data from all of the columns, we could have replaced the list with the wildcard "*", but the output from such a query would not be stable long-term if more columns were added:

Often, getting all of the data is not what we want, but there are ways of tailoring and manipulating the returned data set using WHERE, ORDER BY, GROUP BY/HAVING and other methods.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement