ORACLE 11G - Query to retrieve between a returned range.

table data look like the following:



RNK_ID    RNK         RNK_RANGE
1      E1      1
2      E2      2
3      E3      3
4      E4      4
5      E5      5
6      E6      6
7      E7      7
8      E8      8
9      E9      9
10      W1      10
11      W2      11
12      W3      12
13      W4      13
14      W5      14
15      O1      15
16      O2      16
17      O3      17
18      O4      18
19      O5      20
20      O6      21
21      O9      22

The values 'E4' and 'O3' values will be passed  from the main query to the following sub query for example:
SELECT RNK_RANGE FROM
          RANK_LOOKUP LK            
       where
       LK.RNK = 'E4'  OR  LK.RNK= 'O3'

From the dataset abover, the results returned will be 4 and 17.

I want to modify the query to also return the values between RNK_RANGE 4 AND 17.
cookiejarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Is this not really the same as your previous question?

What is your RNK_ID or RNK column based on?

I suggest you either keep going with this question and close the other out or delete this one and continue with the other one.

0
HainKurtSr. System AnalystCommented:
try this:

select *
from RANK_LOOKUP a inner join
(
select min(RNK_RANGE) r1, max(RNK_RANGE) r2 from RANK_LOOKUP where RNK in ('E4','O3')
) b on a.rnk_range between r1 and r2
0
HainKurtSr. System AnalystCommented:
or this:

select *
from RANK_LOOKUP
where rnk_range between
(select min(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
and
(select max(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cookiejarAuthor Commented:
How would I construct the in ('E4','O3') when I am passing the column name min_rank for ‘E4’ and the column name max_rank for ‘O3’?  Would it look like ‘(‘ || min_rank || , || max_rank || ‘)’  I am not savvy with constructing the comma delimiter and single quote correct syntax.
0
HainKurtSr. System AnalystCommented:
like this:

RNK in (min_rank, max_rank)

no need for '
0
cookiejarAuthor Commented:
In addition, to use this statement to retrieve ranks that are not within this range would I change the in ('E4','O3') to not in ('E4','O3')
 
from RANK_LOOKUP
where rnk_range between
(select min(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
and
(select max(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))

0
HainKurtSr. System AnalystCommented:
use not between...

from RANK_LOOKUP
where rnk_range NOT between
(select min(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
and
(select max(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
0
HainKurtSr. System AnalystCommented:
or use > < operators

NOT between :

from RANK_LOOKUP
where
rnk_range < (select min(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
and
rnk_range > (select max(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))

between :

from RANK_LOOKUP
where
rnk_range >= (select min(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
and
rnk_range <= (select max(RNK_RANGE) from RANK_LOOKUP where RNK in ('E4','O3'))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.