Board index » delphi » UNION Don't Like ORDER BY in Interbase SQL

UNION Don't Like ORDER BY in Interbase SQL

Hi,
I tried to write a query in Interbase wich looks like this
 Select  <Colums>
 from tablex
 where <Cond>
Union
 Select <Same Colums>
 from tabley
 where <Cond>
Order By <Col>
This Query don't worl on Interbase SQL, I can't use Order By with Union,
So I tried tu use Views, but Create View don't accept UNION,
so my question is how to sort a query that contain a Union clause
Thanks
 

Re:UNION Don't Like ORDER BY in Interbase SQL


Quote
Lotfi ZEMALI wrote:

> This Query don't worl on Interbase SQL, I can't use Order By with Union,

        It will work, but you have to specify the column in the ORDER BY
numerically, i.e., ORDER BY 1

Quote
> So I tried tu use Views, but Create View don't accept UNION,

        It should in IB 6.

        HTH,

        -Craig

--
Craig Stuntz               Vertex Systems Corporation
Senior Developer           http://www.vertexsoftware.com

Delphi/InterBase weblog:   http://delphi.weblogs.com

Re:UNION Don't Like ORDER BY in Interbase SQL


Lotfi ZEMALI escribi en mensaje <3a27fdc5_2@dnews>...

Quote
>Hi,
>I tried to write a query in Interbase wich looks like this
> Select  <Colums>
> from tablex
> where <Cond>
>Union
> Select <Same Colums>
> from tabley
> where <Cond>
>Order By <Col>

<Col> is ordinal number or column name ? You should use ordinal name since
you are mixing data from diferent tables.
Quote
>This Query don't worl on Interbase SQL, I can't use Order By with Union,
>So I tried tu use Views, but Create View don't accept UNION,
>so my question is how to sort a query that contain a Union clause
>Thanks

Re:UNION Don't Like ORDER BY in Interbase SQL


Quote
> >Order By <Col>

> <Col> is ordinal number or column name ? You should use ordinal name since
> you are mixing data from diferent tables.

I tried both, but no use

Re:UNION Don't Like ORDER BY in Interbase SQL


Hi,
Sorry now it work
So thank you very much

Other Threads