Problems with UNION ALL and ORDER BY

From: Kaloyan Iliev Iliev <news1(at)faith(dot)digsys(dot)bg>
To: pgsql-sql(at)postgresql(dot)org
Subject: Problems with UNION ALL and ORDER BY
Date: 2004-08-02 15:53:26
Message-ID: 410E6376.1010404@faith.digsys.bg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Dear friends...,
I have the following problem:

select
.....
from
....
where
....
UNION ALL

select
...
from
....
where
....
ORDER BY field1

But the the order by doesn't work properly. It returns the rows of the
first query ordered and then appends the rows of the second query
ordered. But this is not what i expect. I expect the result of both
queries to be orderd. So I try.

SELECT TEMP.*
FROM
(
select
.....
from
....
where
....
UNION ALL

select
...
from
....
where
....
) TEMP
ORDER BY TEMP.field1

But this also doesn't work. Any ideas.p

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kaloyan Iliev Iliev 2004-08-02 16:09:04 Problems with UNION ALL and ORDER BY
Previous Message Ray Aspeitia 2004-08-02 13:00:44 Re: How to create an aggregate?