Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Query problem
Alesk,
Tom has posted suitable queries for you to use, but let me try to explain the syntax error.
You should consider the AS as just a heading for the output. The column is not "known" by the name within the query, except for the ORDER BY clause.
Basically, in both SQL Server and ANSI SQL, the output of a query is a virtual table. Because the virtual table does not exist until the query has completed execution, the column titles of the virtual table can not be referenced within the query.
Ok, so why can one use the column title in the ORDER BY clause ...
Because the ORDER BY operates on the virtual table that has been generated. The ORDER BY **has** to have the entire virtual table present before it can sequence the rows, so logically the virtual table exists and thus the ORDER BY is the only clause within the SELECT that can reference columns by the column titles.
Alesk <alesk_at_enter-net.com> wrote in message
news:wYbZ4.386$WL3.90794_at_carnaval.risq.qc.ca...
> Hi!
>
> I want to generate a list of names. The condition is the first letter of the
> last name.
>
> My query looks like this:
>
> Select userid,lname,fname, telno, substring(lname,1,1) AS FLetter from
> <TABLE>
> where Fletter = '<Letter'>.
>
> It doesn't work, saying I have a syntax error near my 'where clause'.
>
> Can anyone help me?
>
> Alesk
>
>
Received on Wed May 31 2000 - 00:00:00 CDT