Evgeny Gopengauz (evgop@ucs.ru) writes:
> Thank you for your answer!
> I'm sorry for the stupid quiestion, I just found the answer in the "FROM
> clause" of BOL. But when I read it in the first time I didn't guess that
> "derived_table" is the same as subquery and alias is required.
Derived table and subqueries are not the same. :-)
A derived table is something you can use where can have a table, that is
in a FROM clause. A subquery can appear in an expression, for instance:
SELECT x, (SELECT MAX(y) FROM a WHERE a.id = b.id)
FROM a
WHERE col = (SELECT MAX(z) FROM c)
Here are two subqueries, of which the first is correlated with the main
query, the other is not.
A derived table is always uncorrelated.
By the way:
CREATE TABLE
transactions(
currencyID_1 int,
value_1 money,
currencyID_2 int,
value_2 money
)
This is the point where I play Joe Celko and point out that using
integer ids for currencies is a bad thing. Currencies is one of the
few entities that actually has stable useful natural keys, as defined
by ISO 4217. (See for instance
http://www.xe.com/iso4217.htm.)
--
Erland Sommarskog, SQL Server MVP,
esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp