×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
select * from test a
where n1 = (select Min(n1) from test where a.id = id)
or n2 = (select Min(n2) from test where a.id = id)
will return...
ID N1 N2
C1 4 0
C1 2 0
Mr. Morgan's modification to accommodate the point I missed will result in the same set of data.
Mr. Berendt's solution seems closer...his result set (with the extra record Paul pointed out) is...
select * from test a
where n1 = (select Min(n1) from test where a.id = id)
or n2 = (select Min(n2) from test where a.id = id and n2 <> 0)
ID N1 N2
C1 3 4
C1 2 0
steve
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Morgan, Paul
Sent: Wednesday, February 09, 2011 8:38 AM
To: Midrange Systems Technical Discussion
Subject: RE: impossible sql request
David,
Steve's answer is close and gives the lines with the lowest values for n1 or n2.
Do you also want to select lowest n1 only for lines where n2 is zero?
select *
from test a
where n1 = ( select Min( n1 )
from test
where a.id = id
and n2 = 0 )
or n2 = ( select Min( n2 )
from test
where a.id = id )
If you had a line of:
C1 2 0
would you expect to only get that one line?
Paul Morgan
Principal Programmer Analyst
IT Supply Chain/Replenishment
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Needles,Stephen J
Sent: Wednesday, February 09, 2011 9:06 AM
To: Midrange Systems Technical Discussion
Subject: RE: impossible sql request
select * from test a
where n1 = (select Min(n1) from test where a.id = id)
or n2 = (select Min(n2) from test where a.id = id)
not particularly pretty...but it works.
steve
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of David FOXWELL
Sent: Wednesday, February 09, 2011 7:55 AM
To: Midrange Systems Technical Discussion
Subject: impossible sql request
Hi all,
I need to scan this table and get the lines having the lowest value for n1 or n2
id n1 n2
c1 4 0
c1 3 4
c1 4 5
c1 5 6
If n2 is not 0, I ignore the value of n1.
So in this example I should return 2 lines containing 4 :
c1 4 0
c1 3 4
Thanks
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.