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

Started by Nonameover 24 years ago4 messagesgeneral
Jump to latest
#1Noname
jfc100@btopenworld.com

Hi,

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;

Cheers
Joe

#2Calvin Dodge
caldodge@fpcc.net
In reply to: Noname (#1)
Re: Filtering a bunch of records to one after a selection has returned a bunch of them

jfc100@btopenworld.com (Joe) wrote in message news:<88d9f4b3.0112270701.4a3741d@posting.google.com>...

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;

Ummm ... "select something from thistable limit 1".

Or is there something I'm missing here?

Calvin

#3Nevermind
never@nevermind.kiev.ua
In reply to: Noname (#1)
Re: Filtering a bunch of records to one after a selection has returned a bunch of them

Hello, Joe!

On Thu, Dec 27, 2001 at 07:01:16AM -0800, you wrote:

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 min(counter) from my_table limit 1;

--
NEVE-RIPE

#4Gregory Wood
gregw@com-stock.com
In reply to: Noname (#1)
Re: Filtering a bunch of records to one after a selection has returned a bunch of them

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