Sei sulla pagina 1di 1

Chapter 3: Selecting 101

Note: The comma join operator should be avoided. The other join operators,
like INNER JOIN, and the ON condition make FROM clauses much easier to
understand. In this particular case, however, the comma join operator must be
used, and it can be thought of as working like an INNER JOIN.

Tip: Procedure calls in FROM clauses may be called once or a million times,
depending on how theyre coded. You can easily confirm how many times a pro-
cedure is called by adding a MESSAGE statement like the one in the example
above; each call will result in a line displayed in the database engine console.

3.9 SELECT List


The second step in the logical execution of a select is to evaluate all the select
list items, except for aggregate function and NUMBER(*) calls, and append the
values to each row in the virtual table that is returned by the FROM clause.
<select_list> ::= <select_item> { "," <select_item> }
<select_item> ::= "*"
| [ <owner_name> "." ] <table_name> "." "*"
| <correlation_name> "." "*"
| <expression>
| <expression> [ AS ] <select_item_alias>
<select_item_alias> ::= <alias_name> -- very useful
| <string_literal> -- not so useful
<string_literal> ::= a sequence of characters enclosed in single quotes
The asterisk "*" represents all the columns from all the tables in the FROM
clause, in the order the tables were specified in the FROM clause, and for each
table, in the order the columns were specified in the CREATE TABLE
statement.
The "*" notation may be combined with other select list items; i.e., you
arent limited to SELECT * FROM .... This is sometimes useful for quick que-
ries to show me the product name column, plus all the other columns in the
table in case I want to look at them as in the following example:
SELECT product.name,
*
FROM product
INNER JOIN sales_order_items
ON sales_order_items.prod_id = product.id
INNER JOIN sales_order
ON sales_order.id = sales_order_items.id
ORDER BY product.name,
sales_order.order_date DESC;
You can qualify a table name with ".*" to represent all the columns in this par-
ticular table, in the order they were specified in the CREATE TABLE statement.
Theres no restriction on repetition in the select list. Here is an example of a
query to show me the product name, plus all the columns in sales_order_items,
plus all the columns in all the tables in case I want to look at them:
SELECT product.name,
sales_order_items.*,
*
FROM product
INNER JOIN sales_order_items
ON sales_order_items.prod_id = product.id
INNER JOIN sales_order

Potrebbero piacerti anche