X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8852DD1B209 for ; Mon, 2 Aug 2004 13:48:17 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10716-06 for ; Mon, 2 Aug 2004 16:48:13 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id ED8C5D1B1DC for ; Mon, 2 Aug 2004 13:48:12 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i72GmBqd020684 for ; Mon, 2 Aug 2004 16:48:12 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i72GkJ7o020485 for pgsql-sql@postgresql.org; Mon, 2 Aug 2004 16:46:19 GMT From: Gaetano Mendola X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Problems with UNION ALL and ORDER BY Date: Mon, 02 Aug 2004 18:45:50 +0200 Organization: PYRENET Midi-pyrenees Provider Lines: 37 Message-ID: <410E6FBE.9000103@bigfoot.com> References: <410E6376.1010404@faith.digsys.bg> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@pyrenet.fr To: Kaloyan Iliev Iliev User-Agent: Mozilla Thunderbird 0.7.1 (Windows/20040626) X-Accept-Language: en-us, en In-Reply-To: <410E6376.1010404@faith.digsys.bg> X-Enigmail-Version: 0.84.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/11 X-Sequence-Number: 18508 Kaloyan Iliev Iliev wrote: > > 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 This have to work. Could you please provide a real example ( creation table, insertion data and query execution ). Regards Gaetano Mendola