[quoted text, click to view] "Joe Celko" <jcelko212@earthlink.net> wrote in message
news:%23y8D9VliEHA.2908@TK2MSFTNGP10.phx.gbl...
> The syntax of a UNION in SQL says that result of a UNION [ALL] has no
> column names.
Can you please give a reference or a quote from the standard document for
this?
I thought Section 7.10, syntax rule 12)b)i) of the SQL-92 standard applied,
and while the version I have with me may not be the final one, it doesn't
say what you say. The specification basically says this (for UNION queries
with no CORRESPONDING clause): if the i-th column has the same name in every
one of the individual tables, then the i-th column of the result has that
name. Otherwise, the i-th column name must differ from the name of any [not
i]-th column of any of the individual tables, but is otherwise
implementation-dependent.
Steve Kass
Drew University
You need to write it as :
[quoted text, click to view] >
> SELECT X.*
> FROM (SELECT .. FROM Foo WHERE ..
> UNION
> SELECT .. FROM Bar WHERE ..)
> AS X(..)
>
> Then put an AS clause on the entire result, giving it a table name and
> column names.
>
> And real SQL programmers follow iSO-11179 rules and do not put crap like
> "vw_" prefixes on things, unless they really do relate to a Volkswagen.
> They also avoid proprietary code, which means UDFs, SELECT TOP and
> getdate().
>
> --CELKO--
> ===========================
> Please post DDL, so that people do not have to guess what the keys,
> constraints, Declarative Referential Integrity, datatypes, etc. in your
> schema are.
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!