Subject Re: [firebird-support] Sql query help
Author Helen Borrie
At 05:06 AM 22/01/2004 +0000, you wrote:
>Hello All,
> May be this is easy, but I'm not able to figure it out, as to to how
> this can be solved.
>I've a select procedure, which returns me a resultset
>
>create procedure...
>begin
> for select col1, col2 from table1 where col1=<const> order by col1
> do
> suspend;
>end
>
>This is working fine. But if a union query instead of a single query is
>used, the stored procedure gives compilation error
>'invalid ORDER BY clause' or 'Token unknown union'
>
>create procedure...
>begin
> for
> select col1, col2 from table1 where col1=<const> order by col1
> union
> select col1, col2 from table1 where col1=<const> order by col1
> do
> suspend;
>end
>
>If I remove the order by clause, it works fine. What I want, is that the
>total resulset should be sorted.
>Can someone help me out to figure this?

Yup - you can only have one ORDER BY clause and it has to come after all of
the unions (and before the INTO of course).

/hb