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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:48:10+00:00 2026-05-13T12:48:10+00:00

I have two tables table1 and table2. Table2 is having less number of rows

  • 0

I have two tables table1 and table2. Table2 is having less number of rows than table1. In these two tables there are two date columns caldate1 in table1 and caldate2 in table2. So now I need to join on these two tables and get the maximum of the two date columns and keep that in new table. But if we inner join on these two tables the table1 rows which are not there in table2 will not go into the final table. So we need some thing like

table1 
left outer join
table2

But there is a situation that the two dates are having nulls. So Can I use coalesce to get the correct data in the below scenarios..

1. row in table1 is not there in table2 -> then the caldate1 in table1 should go into final table.

2. row in table1 is there in table2 and the caldate1 of table1 and caldate2 of table2 are nulls -> then null should come into final table’s date column

3. row in table1 is there in table2 and caldate1 is not null and caldate2 is null -> then caldate1 should come into final table.

4. row in table1 is there in table2 and caldate1 is null and caldate2 is not null -> then caldate2 should come into final table

5. row in table1 is there in table2 and caldate1 is greater than caldate2 -> caldate1 should come into final table

6. row in table1 is there in table2 and caldate2 is greater than caldate1 -> caldate2 should come into final table

We dont need to consider the rows in table2 which are not matching with table1. So basically i need all table1 rows with latest of the caldate if a particular row is there in both tables. Thanks in advance. I am not able to get correct function to do it.Is it coalesce?

  • 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-13T12:48:11+00:00Added an answer on May 13, 2026 at 12:48 pm

    I am thinking of doing something like below to satisfy my requirement.

    SELECT 
    a.number,
    CASE WHEN ZEROIFNULL(a.caldate1) > ZEROIFNULL(b.caldate2)
    THEN a.caldate1  -- This is working
    ELSE
    b.caldate2
    END AS caldate
    /*COALESCE (a.caldate1,caldate2) AS caldate*/ -- This is not giving max of dates
    FROM 
    table1  a
    LEFT OUTER JOIN
    table2  b
    ON
    a.number = b.number
    

    Thanks for helping. Now its done by the above method.

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

Sidebar

Related Questions

No related questions found

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.