X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BFA7C9DCC1F for ; Fri, 24 Mar 2006 17:00:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47209-06 for ; Fri, 24 Mar 2006 17:00:39 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 729079DCA32 for ; Fri, 24 Mar 2006 17:00:34 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k2OL0Zlt009559; Fri, 24 Mar 2006 16:00:35 -0500 (EST) To: Amos Hayes cc: pgsql-sql@postgresql.org Subject: Re: Find min and max values across two columns? In-reply-to: References: Comments: In-reply-to Amos Hayes message dated "Fri, 24 Mar 2006 15:19:38 -0500" Date: Fri, 24 Mar 2006 16:00:35 -0500 Message-ID: <9558.1143234035@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.114 required=5 tests=[AWL=0.114] X-Spam-Score: 0.114 X-Spam-Level: X-Archive-Number: 200603/394 X-Sequence-Number: 24740 Amos Hayes writes: > I'm trying to build a query that among other things, returns the > minimum and maximum values contained in either of two columns. I think you might be looking for select greatest(max(columnA), max(columnB)) from tab; select least(min(columnA), min(columnB)) from tab; greatest/least are relatively new but you can roll your own in older PG releases. regards, tom lane