Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7028895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:28:02+00:00 2026-05-28T00:28:02+00:00

There is a table in Oracle with the columns: id | start_number | end_number

  • 0

There is a table in Oracle with the columns:

id | start_number | end_number
---+--------------+------------
1  | 100          | 200
2  | 151          | 200
3  | 25           | 49
4  | 98           | 99  
5  | 49           | 100

There is a list of numbers (50, 99, 150).

I want an sql statement that returns all the ids where any of the numbers in the list of numbers is found equal to or between the start_number and the end_number.

Using the above example; 1, 4 and 5 should be returned.
1 – 150 is between or equal to 100 and 200
2 – none of the numbers are between or equal to 151 and 200
3 – none of the numbers are between or equal to 25 and 49
4 – 99 is between or equal to 98 and 99
5 – 50 and 99 are between or equal to 49 and 100

drop table TEMP_TABLE;

create table TEMP_TABLE(
THE_ID number,
THE_START number,
THE_END number
);

insert into TEMP_TABLE(THE_ID, THE_START, THE_END) values (1, 100, 200);
insert into TEMP_TABLE(THE_ID, THE_START, THE_END) values (2, 151, 200);
insert into TEMP_TABLE(THE_ID, THE_START, THE_END) values (3, 25, 49);
insert into TEMP_TABLE(THE_ID, THE_START, THE_END) values (4, 98, 99);
insert into TEMP_TABLE(the_id, the_start, the_end) values (5, 49, 100);

The following is the solution I came up with based on the comments and answers below plus some additional research:

SELECT
*
from
TEMP_TABLE
where
EXISTS (select * from(
select column_value as id 
from table(SYS.DBMS_DEBUG_VC2COLL(50,99,150)) 
)
where id
BETWEEN TEMP_TABLE.the_start AND TEMP_TABLE.the_end
)

This works too:

SELECT
*
from
TEMP_TABLE
where
EXISTS (select * from(
select column_value as id 
from table(sys.ku$_vcnt(50,99,150)) 
)
where id
BETWEEN TEMP_TABLE.the_start AND TEMP_TABLE.the_end
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:28:02+00:00Added an answer on May 28, 2026 at 12:28 am

    It partly depends on how your are storing your list of numbers. I’ll assume that they’re in another table for now, as even then you have many options.

    SELECT
      *
    FROM
      yourTable
    WHERE
      EXISTS (SELECT * FROM yourList WHERE number BETWEEN yourTable.start_number AND yourTable.end_number)
    

    Or…

    SELECT
      *
    FROM
      yourTable
    INNER JOIN
      yourList
        ON yourList.number BETWEEN yourTable.start_number AND yourTable.end_number
    

    Both of those are the simplest expressions, and work well for small data sets. If your list of numbers is relatively small, and your original data is relatively large, however, this may not scale well. This is because both of the above scan the whole of yourTable and then check each record against yourList.

    What may be preferable is to scan the list, and then attempt to use indexes to check against the original data. This would require you to be able to reverse the BETWEEN statement to yourTable.start_number BETWEEN x and y

    This can only be done if you know the maximum gap between start_number and end_number.

    SELECT
      *
    FROM
      yourList
    INNER JOIN
      yourTable
        ON  yourTable.end_number   >= yourList.number
        AND yourTable.start_number <= yourList.number
        AND yourTable.start_number >= yourList.number - max_gap
    

    To achieve this I would store the value of max_gap in another table, and update it as the values in yourTable change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Oracle table there are columns with different type. I want to read
I have an Oracle table with two columns ID and START_DATE, I want to
Yesterday I wanted to add a boolean field to an Oracle table. However, there
in an sql table there's an id, first name and last name field. i'd
There is a table: doc_id(integer)-value(integer) Approximate 100.000 doc_id and 27.000.000 rows. Majority query on
I'm having trouble trying to define the SQL query for this table: There's a
In oracle: I have a table rel with these columns (object_id1, object_id2) that relates
How can I get all columns' names from an Oracle table using Java? Is
Is there any way to move an column in an Oracle table from last
I need to upload some data from an Oracle table to a SQL Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.