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 8AB7DD1B171 for ; Mon, 2 Aug 2004 12:57:28 -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 84949-06 for ; Mon, 2 Aug 2004 15:57:23 +0000 (GMT) Received: from school.digsys.bg (school.digsys.bg [193.68.6.1]) by svr1.postgresql.org (Postfix) with ESMTP id 4D1FDD1B1B9 for ; Mon, 2 Aug 2004 12:57:16 -0300 (ADT) Received: from faith.digsys.bg (root@www1.digsys.bg [193.68.6.128]) by school.digsys.bg (8.11.6/8.10.1) with ESMTP id i72FvCE22427 for ; Mon, 2 Aug 2004 18:57:14 +0300 (EEST) Message-ID: <410E6376.1010404@faith.digsys.bg> Date: Mon, 02 Aug 2004 18:53:26 +0300 From: Kaloyan Iliev Iliev User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040115 X-Accept-Language: en-us, en, bg MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Problems with UNION ALL and ORDER BY Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/7 X-Sequence-Number: 18504 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