SQL SELECT FROM statement
Projection
The weather table stores information about the weather in London for the past five days and looks like this:
A query that selects only the basic info to be displayed on a mobile phone screen, for example, day, hour, weather phenomena, temperature, feels like, and wind speed, will look like this:
After the SELECT keyword, list the columns to select and specify aliases where needed.
The query evaluation results in the following table:
The type of data extraction selected for a subset of table columns is called projection.
The general layout for such queries: the SELECT statement, list of column names with optional aliases, FROM, table name, and a semicolon to mark the end of the statement:
Expressions
To have different results based on the same data, add columns that state the place and show the temperature in Fahrenheit:
The query below does this:
When the data management system executes the query, it will substitute the column names with the corresponding attribute value for each processed row.
Logical table
A data management system hides how the data is physically stored behind an abstract concept of a logical table. To run a query, it is required to know the database schema—table names, column names, and types—and appropriate access permissions. Internally, the query processor maps table and column references from queries to physical data such as files, network connections, and even the results of executing other queries.
SQL SELECT FROM template
The overall template for statements that extract data from a table and evaluate expressions in it consists of the SELECT keyword, list of expressions with optional aliases, FROM, table name, and a semicolon to mark the end of the statement.