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 34B3E8B9D49 for ; Wed, 23 Feb 2005 17:04:47 +0000 (GMT) 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 65394-02 for ; Wed, 23 Feb 2005 17:04:37 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id C92CD8B9CC0 for ; Wed, 23 Feb 2005 17:04:35 +0000 (GMT) Received: (qmail 15920 invoked by uid 500); 23 Feb 2005 17:19:57 -0000 Date: Wed, 23 Feb 2005 11:19:57 -0600 From: Bruno Wolff III To: WeiShang Cc: pgsql-sql@postgresql.org Subject: Re: VIEW / ORDER BY + UNION Message-ID: <20050223171957.GA15830@wolff.to> Mail-Followup-To: WeiShang , pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.11 tagged_above=0 required=5 tests=AWL, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200502/276 X-Sequence-Number: 20386 On Thu, Feb 17, 2005 at 23:46:59 +0800, WeiShang wrote: > Hi, I have created a view like this : > > CREATE VIEW v1 AS (SELECT orderno,weekday,time FROM t1,t2 where > t1.orderno=t2.orderno); > > if I create a SQL statment: > > (SELECT orderno FROM v1 WHERE weekday='MON' ORDER BY orderno) > UNION > (SELECT orderno FROM v1 WHERE weekday='WED' ORDER BY orderno) > UNION > (SELECT orderno FROM v1 WHERE weekday='FRI' ORDER BY orderno); > > Will the whole result will be sorted by the field orderno? If this isn't a made up example, you don't want to do this. You should use IN or OR to select records corresponding to the days of interest and then use ORDER BY to select the ordering.