Re: Filtering a bunch of records to one after a selection has returned a bunch of them - Mailing list pgsql-general

From Gregory Wood
Subject Re: Filtering a bunch of records to one after a selection has returned a bunch of them
Date
Msg-id 005d01c19483$a29bca30$7889ffcc@comstock.com
Whole thread Raw
In response to Filtering a bunch of records to one after a selection has returned a bunch of them  (jfc100@btopenworld.com (Joe))
List 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



pgsql-general by date:

Previous
From: Chris Albertson
Date:
Subject: Re: Installing postgresql on Win2K
Next
From: "Ben-Nes Michael"
Date:
Subject: Simplicity in time/date functions