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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:10:52+00:00 2026-05-31T06:10:52+00:00

I have a table with (among other things) dates in a field. I need

  • 0

I have a table with (among other things) dates in a field.

I need to get a list of all dates that are more recent than the oldest date, older than the most recent date, and are completely missing from the table.

So, if the table contained:

2012-01-02
2012-01-02
2012-01-03
2012-01-05
2012-01-05
2012-01-07
2012-01-08

I want a query that returns:

2012-01-04
2012-01-06
  • 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-31T06:10:54+00:00Added an answer on May 31, 2026 at 6:10 am

    Something like this (assuming your table is named your_table and the date column is named the_date):

    with date_range as (
          select min(the_date) as oldest, 
                 max(the_date) as recent, 
                 max(the_date) - min(the_date) as total_days
          from your_table
    ),
    all_dates as (
       select oldest + level - 1 as a_date
       from date_range
       connect by level <= (select total_days from date_range)
    )
    select ad.a_date
    from all_dates ad
      left join your_table yt on ad.a_date = yt.the_date
    where yt.the_date is null
    order by ad.a_date;  
    

    Edit:
    the WITH clause is called a “common table expression” and is equivalent to a derived table (“inline view”).

    It’s similar to

    select * 
    from ( 
         ..... 
    ) all_dates
    join your_table ...
    

    The second CTE simply creates a list of dates “on-the-fly” using a undocumented feature of Oracle’s connect by implementation.

    Re-using a select (like I did with calculating the first and last date) is a bit easier (and IMHO more readable) than using derived tables.

    Edit 2:

    This can be done with a recursive CTE as well:

    with date_range as (
          select min(the_date) as oldest, 
                 max(the_date) as recent, 
                 max(the_date) - min(the_date) as total_days
          from your_table
    ),
    all_dates (a_date, lvl) as (
       select oldest as a_date, 1 as lvl
       from date_range 
       union all
       select (select oldest from date_range) + lvl, lvl + 1
       from all_dates 
       where lvl < (select total_days from date_range)
    )
    select ad.a_date, lvl
    from all_dates ad    
      left join your_table yt on ad.a_date = yt.the_date
    where yt.the_date is null
    order by ad.a_date;  
    

    Which should work in all DBMS supporting recursive CTEs (PostgreSQL and Firebird – being more standard compliant – do need the recursive keyword though).

    Note the hack select (select oldest from date_range) + lvl, lvl + 1 in the recursive part. This should not be necessary, but Oracle still has some bugs with regards to DATEs in a recursive CTE. In PostgreSQL the following works without problems:

    ....
    all_dates (a_date, lvl) as (
       select oldest as a_date, 0 as lvl
       from date_range 
       union all
       select a_date + 1, lvl + 1
       from all_dates 
       where lvl < (select total_days from date_range)
    )
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that consists of, among other things, two fields named StartTime
I have a database table that contains among other things partial postal codes. I'm
I have a table that contains, among other things, about 30 columns of boolean
I have a view that - among other things - contains a list of
Simply put, I have a table with, among other things, a column for timestamps.
If I have a table that (among other columns) has two DATETIME columns, how
I have a function that returns a table. The returned table contains (among other
i have a static library which (among other things) implements a tiny function that
I have a table that contains procedure codes among other data (let's call it
I have a table with (among other things) a name and a rank. I'd

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.