Sie sind auf Seite 1von 1

102 Chapter 3: Selecting

ON sales_order.id = sales_order_items.id
ORDER BY product.name,
sales_order.order_date DESC;

Tip: In application programs it is usually a better idea to explicitly list all the
column names in the select list rather than use the asterisk "*" notation.

An individual item (i.e., something not using the asterisk "*" notation) in a
select list may be assigned an alias name. This name may be used elsewhere in
the select list and in other clauses to refer back to this select list item. In the case
of a column name in a select list, the alias name is optional because with or
without an alias name, the column name itself may be used to refer to that item.
For a select list item that is an expression, an alias name is required if that select
list item is to be referred to by name in another location.

Tip: The keyword AS may be optional but it should always be used when
defining alias names to make it clear to the reader which is the alias name and
which is the select list item.

Tip: Use identifiers as alias names, not string literals. Only the select list
allows a string literal as an alias, and if you use that facility you cant refer to the
alias from other locations. In all the other locations where alias names may be
used (in derived table definitions, CREATE VIEW statements, and WITH clauses,
for example), only identifiers may be used, and thats what you should use in the
select list.

Individual items in the select list, such as expressions and column references,
are explained in detail in the following sections.

3.10 Expressions and Operators


A select list can be more than asterisks and column names; you can use vastly
more complex expressions as long as each one returns a single value when it is
evaluated. In fact, the simple <column_reference> is almost lost in the syntax
for <expression>:
<expression> ::= <basic_expression>
| <subquery>
<basic_expression> ::= <simple_expression>
| <if_expression>
| <case_expression>
<simple_expression> ::= "(" <basic_expression> ")" -- Precedence:
| "-" <expression> -- 1. unary minus
| "+" <expression> -- 1. unary plus
| "~" <expression> -- 1. bitwise NOT
| <simple_expression> "&" <expression> -- 2. bitwise AND
| <simple_expression> "|" <expression> -- 2. bitwise OR
| <simple_expression> "^" <expression> -- 2. bitwise XOR
| <simple_expression> "*" <expression> -- 3. multiply
| <simple_expression> "/" <expression> -- 3. divide
| <simple_expression> "+" <expression> -- 4. add
| <simple_expression> "-" <expression> -- 4. subtract
| <simple_expression> "||" <expression> -- 5. concatenate
| <column_reference>
| <variable_reference>
| <string_literal>

Das könnte Ihnen auch gefallen