Lec1 Writing Basic SQL SELECT Statements
Lec1 Writing Basic SQL SELECT Statements
Writing Basic
SQL SELECT Statements
Objectives
KEYWORD MEANING
SELECT is a list of one or more columns
* selects all columns
DISTINCT suppresses duplicates
column|expression selects the named column or the
expression
alias gives selected columns different
headings
FROM table specifies the table containing the
columns
Selecting All Columns
Selecting Specific Columns
Arithmetic Expressions
Note:
Resultant calculated column SALARY+300 is not a new column in the
EMPLOYEES table; it is for display only. By default, the name of a new column
comes from the calculation that generated it— in this case, salary+300.
Operator Precedence
A column alias:
• Renames a column heading
• Is useful with calculations
• Immediately follows the column name: there can
also be the optional AS keyword between the
column name and alias
• Requires double quotation marks if it contains
spaces or special characters or is case sensitive
Using Column Aliases
Concatenation Operator
A concatenation operator:
• Concatenates columns or character strings to
other columns
• Is represented by two vertical bars (||)
• Creates a resultant column that is a character
expression
Using the Concatenation Operator
Literal Character Strings