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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:47:39+00:00 2026-05-18T03:47:39+00:00

I have a series of dates associated with a unique identifier in a table.

  • 0

I have a series of dates associated with a unique identifier in a table. For example:

1 | 1999-04-01 | 0000-00-00 | 0000-00-00 | 0000-00-00   | 2008-12-01 | 
2 | 1999-04-06 | 2000-04-01 | 0000-00-00 | 0000-00-00   | 2010-04-03 | 
3 | 1999-01-09 | 0000-00-00 | 0000-00-00 | 0000-00-00   | 2007-09-03 | 
4 | 1999-01-01 | 0000-00-00 | 1997-01-01 | 0000-00-00   | 2002-01-04 | 

Is there a way, to select the earliest date from the predefined list of DATE fields using a straightforward SQL command?

So the expected output would be:

1 | 1999-04-01
2 | 1999-04-06
3 | 1998-01-09
4 | 1997-01-01

I am guessing this is not possible but I wanted to ask and make sure. My current solution in mind involves putting all the dates in a temporary table and then using that to get the MIN()

thanks

Edit: The problem with using LEAST() as stated is that the new behaviour is to return NULL if any of the columns in NULL. In a series of dates like the dataset in question, any date might be NULL. I would like to obtain the earliest actual date from the set of dates.

SOLUTION: Used a combination of LEAST() and IF() in order to filter out NULL dates.

 SELECT LEAST( IF(date1=0,NOW(),date1), IF(date2=0,NOW(),date2), [...] );

Lessons learnt a) COALESCE does not treat ‘0000-00-00’ as a NULL date, b) LEAST will return ‘0000-00-00’ as the smallest value – I would guess this is due to internal integer comparison(?)

  • 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-18T03:47:39+00:00Added an answer on May 18, 2026 at 3:47 am
    select id, least(date_col_a, date_col_b, date_col_c) from table
    

    upd

    select id, least (
      case when date_col_a = '0000-00-00' then  now() + interval 100 year else date_col_a end,
      case when date_col_b = '0000-00-00' then  now() + interval 100 year else date_col_b end) from table
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table containing a series of names, events and dates. I've created
So I have a MySQL table with a series of dates which formatted as
I have imported a time series with dates of the following format: test =
I have a series of ranges with start dates and end dates. I want
I have a series of tables partitioned by dates and named in the following
I have an Array that returns a requested series of dates that I would
I have read in a series of 37 dates and times that an event
If I have a series of dates in the following format ( YYYY-mm-dd )
Say for example I have a set of dates and a set of numbers
I have a table in a database with one column containing dates and another

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.