Re: Find min and max values across two columns?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Amos Hayes <ahayes(at)polkaroo(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Find min and max values across two columns?
Date: 2006-03-24 21:00:35
Message-ID: 9558.1143234035@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Amos Hayes <ahayes(at)polkaroo(dot)net> 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Rod Taylor 2006-03-24 21:20:06 Re: Find min and max values across two columns?
Previous Message Tom Lane 2006-03-24 20:58:10 Re: Custom type