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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:04:38+00:00 2026-06-14T11:04:38+00:00

I have a table that has a series of time based events, each bound

  • 0

I have a table that has a series of time based events, each bound with a start and end date. For the most recent (current) event, the end date is NULL. Im trying to collapse the duplicative rows and only show the earliest start date and the latest end date. With the NULL being in the date field, that row is ignored. I can dummy up an end date value with NVL(), but that will cause the front end logic to search for and replace that value.

Is there anyway to get max() function to sort NULL as high?

CREATE TABLE CONG_MEMBER_TERM
(
  CONG_MEMBER_TERM_ID  NUMBER(10)               NOT NULL,
  CHAMBER_CD           VARCHAR2(30 BYTE)        NOT NULL,
  CONG_MEMBER_ID       NUMBER(10)               NOT NULL,
  STATE_CD             CHAR(2 BYTE)             NOT NULL,
  DISTRICT             NUMBER(10),
  START_DT             TIMESTAMP(6) WITH TIME ZONE,
  END_DT               TIMESTAMP(6) WITH TIME ZONE
)

This query works, but drops the row where end date is NULL.

select CONG_MEMBER_ID, 
       district, 
       min(start_dt), 
       max(end_dt)
  from CONG_MEMBER_TERM
 where CONG_MEMBER_ID = 1716
 group by CONG_MEMBER_ID, district;

This query fixes that, but now I have a “dummy” end date value(9/9/9999). Something I would rather not have to code around.

select CONG_MEMBER_ID, 
       district, 
       min(start_dt), 
       max(nvl(end_dt, to_date('9/9/9999', 'mm/dd/yyyy')))
  from CONG_MEMBER_TERM
 where CONG_MEMBER_ID = 1716
 group by CONG_MEMBER_ID, district;

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-14T11:04:39+00:00Added an answer on June 14, 2026 at 11:04 am

    max(end_dt) keep (dense_rank first order by end_dt desc nulls first)

    upd:

    SQL Fiddle

    Oracle 11g R2 Schema Setup:

    CREATE TABLE t
        (val int, s date, e date)
    ;
    
    INSERT ALL 
        INTO t (val, s, e)
             VALUES (1, sysdate-3, sysdate-2)
        INTO t (val, s, e)
             VALUES (1, sysdate-2, sysdate-1)
        INTO t (val, s, e)
             VALUES (1, sysdate-1, null)
        INTO t (val, s, e)
             VALUES (2, sysdate-1, sysdate-.5)
        INTO t (val, s, e)
             VALUES (2, sysdate-.5, sysdate-.25)
    SELECT * FROM dual
    ;
    

    Query 1:

    select val, min(s), max(e) keep (dense_rank first order by e desc nulls first)
    from t group by val
    

    Results:

    | VAL |                          MIN(S) | MAX(E)KEEP(DENSE_RANKFIRSTORDERBYEDESCNULLSFIRST) |
    ---------------------------------------------------------------------------------------------
    |   1 | November, 13 2012 14:15:46+0000 |                                            (null) |
    |   2 | November, 15 2012 14:15:46+0000 |                   November, 16 2012 08:15:46+0000 |
    
    • 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 has two datetime columns (one for start time and
I have a table that has three different date columns, so I set each
i have a table that has event name and event date. if i want
I have series of records in a table called 'hits' and each record has
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that has duplicate email address, I need to insert just
I have a table that has no primary key, and one cannot be created
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table that has an AUTO_INCREMENT field. Currently, it is also a
I have one table that has sales records and another table that has additional

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.