C
cinnie
hello gurus
This isn't a question as much as it is a beginner's comment on
BETWEEN...AND. As it seems to be used, BETWEEN...AND gives results that are
inclusive at both ends. (BETWEEN 10 and 20 gives values meeting the
conditions... 10 <= Value <= 20). But there are times, especially when
working with intervals, when I might want non-overlapping values like,
say... 10 < Value <= 20, then 20 < Value <= 30, etc. This is easy to do
using... WHERE Value > 10 And Value <= 20 instead of BETWEEN...AND, but it
gets harder when we don't know which of the limits is the lower bound and
which is the upper bound. For example...
SELECT tData.Country
FROM tData
WHERE tData.GDP BETWEEN (SELECT tData.GDP
FROM tData
WHERE tData.Country = 'Nigeria')
AND (SELECT tData.GDP
FROM tData
WHERE tData.Country = 'Kenya');
Now all of you gurus probably know which of these limits is the lower one
and which is the upper, but I don't! If I wanted, say, GDP values that
were... lower bound <= Value < upper bound, I would have to go through
more SQL contortions to get the desired result.
What I'd like to see is an optional phrase that could be attached to the
current BETWEEN...AND operator to make this sort of thing easier, say
something like...
BETWEEN ... AND ... IncExc
(for including the lower limit but excluding the upper limit) or...
BETWEEN ... AND ... ExcExc
(for excluding the both limits) or...
BETWEEN ... AND
(which defaults to the currently used IncInc)
Any thoughts? (or am I all wet?)
This isn't a question as much as it is a beginner's comment on
BETWEEN...AND. As it seems to be used, BETWEEN...AND gives results that are
inclusive at both ends. (BETWEEN 10 and 20 gives values meeting the
conditions... 10 <= Value <= 20). But there are times, especially when
working with intervals, when I might want non-overlapping values like,
say... 10 < Value <= 20, then 20 < Value <= 30, etc. This is easy to do
using... WHERE Value > 10 And Value <= 20 instead of BETWEEN...AND, but it
gets harder when we don't know which of the limits is the lower bound and
which is the upper bound. For example...
SELECT tData.Country
FROM tData
WHERE tData.GDP BETWEEN (SELECT tData.GDP
FROM tData
WHERE tData.Country = 'Nigeria')
AND (SELECT tData.GDP
FROM tData
WHERE tData.Country = 'Kenya');
Now all of you gurus probably know which of these limits is the lower one
and which is the upper, but I don't! If I wanted, say, GDP values that
were... lower bound <= Value < upper bound, I would have to go through
more SQL contortions to get the desired result.
What I'd like to see is an optional phrase that could be attached to the
current BETWEEN...AND operator to make this sort of thing easier, say
something like...
BETWEEN ... AND ... IncExc
(for including the lower limit but excluding the upper limit) or...
BETWEEN ... AND ... ExcExc
(for excluding the both limits) or...
BETWEEN ... AND
(which defaults to the currently used IncInc)
Any thoughts? (or am I all wet?)