Basic SELECT Statement: SELECT Identifies What Columns FROM Identifies Which Table
Basic SELECT Statement: SELECT Identifies What Columns FROM Identifies Which Table
SELECT
SELECT *|{[DISTINCT]
*|{[DISTINCT] column|expression
column|expression [alias],...}
[alias],...}
FROM
FROM table;
table;
SELECT *
FROM departments;
Selecting Specific Columns
+ Add
- Subtract
* Multiply
/ Divide
Using Arithmetic Operators
…
Operator Precedence
…
Using Parentheses
…
Defining a Null Value
A null is a value that is unavailable,
unassigned, unknown, or inapplicable.
A null is not the same as zero or a blank
space.
SELECT last_name, job_id, salary, commis
FROM employees;
…
Null Values
in Arithmetic Expressions
Arithmetic expressions containing a null
value
evaluate to null.
SELECT last_name, 12*salary*commission_pct
FROM employees;
…
Defining a Column Alias
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
SELECT last_name AS name, commission_pct AS comm
FROM employees;
…
Using the Concatenation Operator
…
Using Literal Character Strings
…
Duplicate Rows
…
Eliminating Duplicate Rows
2
Interacting with Script Files
1
D:\temp\emp_sql.htm
3
Interacting with Script Files
DESCRIBE employees
SELECT first_name, last_name, job_id 1
FROM employees;
3 2
Summary