Re: Filtering a bunch of records to one after a selection has returned a bunch of them

From: "Gregory Wood" <gregw(at)com-stock(dot)com>
To: "Joe" <jfc100(at)btopenworld(dot)com>
Cc: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Filtering a bunch of records to one after a selection has returned a bunch of them
Date: 2002-01-03 18:22:40
Message-ID: 005d01c19483$a29bca30$7889ffcc@comstock.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I am trying to establish whether or not it is possible - and how to
> implement the solution - to execute an sql statement and restricting
> the results to a single match even though there may be more than a
> single record which matches the criteria.
>
> e.g. select min(counter) from my_table butonlyone;

SELECT
CASE
WHEN min(my_table.counter) < min(butonlyone.counter) THEN
min(my_table.counter)
ELSE
min(butonlyone.counter)
END AS MinCounter
FROM my_table,butonlyone;

Alternately, you could write a function that takes a number of arguments
(depending on how many you might need... or even an array of values) and
returns the lowest one. That way you could do something like:

SELECT my_min(my_table.counter,butonlyone.counter) AS MinCounter FROM
my_table,butonlyone;

Greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ben-Nes Michael 2002-01-03 19:17:37 Simplicity in time/date functions
Previous Message Chris Albertson 2002-01-03 18:17:53 Re: Installing postgresql on Win2K