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

  • Home
  • SEARCH
  • 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 6255733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:25:12+00:00 2026-05-24T14:25:12+00:00

I have a table in an Oracle database with a timestamp column nextTime and

  • 0

I have a table in an Oracle database with a timestamp column nextTime and a string column destName. There are more columns as well, but only these two are relevant in this case. I’m trying to design a query that will return distinct destName having nextTime within a specific interval and the returned number of rows should be maximum one thousand. When there are more than one thousand distinct destName within the interval I want the query to return one thousand rows, netiher more nor less.

I actually have a query that is working, but it is way too slow:

select destName 
from (select /*+ index(tblDestNames tbldestnames_destname)*/ distinct destName
from (select /*+ index(tblDestNames tbldestnames_nextTime)*/ destName
from tblDestNames 
where nextTime < :1 and nextTime >= :2 and destName is not null)) 
where rownum <= 1000; 

Any ideas on how to design a smarter query or how to optimize this exisiting one are very much appreciated.

  • 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-24T14:25:14+00:00Added an answer on May 24, 2026 at 2:25 pm

    I am not sure that there is a reason not to simplify the query to this:

    select destName 
    from (
        select distinct destName
        from tblDestNames 
        where nextTime < :1 and nextTime >= :2 and destName is not null
        )
    where rownum <= 1000; 
    

    However, this will not solve your performance issue. The problem is this:

    where rownum <= 1000
    

    By replacing rownum with ‘rank’ and ‘over’ you would get something like:

    select distinct destName
    from (
        select
           destName
        from
           (select destName, rank()
            over (order by destName desc ) rnk
            from tblDestNames
            where nextTime < :1 and nextTime >= :2 and destName is not null) 
        where rnk <= 1000;
        )
    

    The bonus is that with ‘over’ you choose the order of the results that will show and the ones that will not show.

    EDIT: Actually it can be further simplified into:

    select
       distinct destName
    from
       (select destName, rank()
        over (order by destName desc ) rnk
        from tblDestNames
        where nextTime < :1 and nextTime >= :2 and destName is not null) 
    where rnk <= 1000;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Oracle database, I have a table called Customers. There are fields for
I have the following table setup in an oracle database: Column Pk_foo1 Column Pk_foo2
I have an Oracle (10.2.0.4) database table with a column which is encrypted by
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have a table in an Oracle Database that has, among others, a DATE
I would like to have a table in my Oracle database whose rows act
I have rows in an Oracle database table which should be unique for a
I have a table in an oracle database with 15 fields. This table had
I have a table CompanyList in my Oracle database : CMP_ID INTEGER -- ID
I have a Oracle database table like so, which records an item being scanned

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.