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 8303951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:40:23+00:00 2026-06-08T17:40:23+00:00

Can this query below be optimized? select max(date), sysdate – max(date) from table; Query

  • 0

Can this query below be optimized?

select
     max(date), sysdate - max(date)
 from
     table;

Query execution time ~5.7 seconds

I have another approach

select
    date, sysdate - date
from
    (select * from table order by date desc)
where
    rownum = 1;

Query execution ~7.9 seconds

In this particular case, table has around 17,000,000 entries.

Is there a more optimal way to rewrite this?

Update: Well, I tried the hint a few of you suggested in a database development, although with a smaller subset than the original (approximately 1,000,000 records). Without the index the queries runs slower than with the index.

The first query, without index: ~0.56 secs, with index: ~0.2 secs. The second query, without index: ~0.41 secs, with index: ~0.005 secs. (This surprised me, I thought the first query would run faster than the second, maybe it’s more suitable for smaller set of records).

I suggested to DBA this solution and he will change the table structure to accommodate this, and then i will test it with the actual data. Thanks

  • 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-06-08T17:40:26+00:00Added an answer on June 8, 2026 at 5:40 pm

    Is there an index on the date column?

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

Sidebar

Related Questions

Can this MS-Access query be improved? i.e. the SELECT TOP 1 col FROM Table2
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
I have this query where I can search the TABLE_GLOBAL_PRODUCTS $catglobal_sql = select p.*,
Can someone explain step by step how this query is processed? SELECT F.ID, F.FirstName,
Having tried this query a million different ways, I can't seem to SELECT 'count_lonely_vehicles'
I have a select query in MySQL shown below: This query executes and produces
Oracle 10g is the db. The below query fails when extracting the date. SELECT
I have this sql: SELECT a.member_id, b.date, b.type, d.K_id, d.title, a.login FROM members as
I have this query to be run: string query = @SELECT * FROM hint
How can I rewrite this query to Doctrine DBAL query or better to createQuery()

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.