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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:57:25+00:00 2026-06-18T15:57:25+00:00

I have a MYSQL database with the following fields (simplified to show issue): id

  • 0

I have a MYSQL database with the following fields (simplified to show issue):

id | courseID | date1      | date2      | date 3     | date 4 
-----------------------------------------------------------------
1  | 10       | 2013-01-01 | 2013-02-05 | 0000-00-00 | 0000-00-00
2  | 23       | 2013-03-02 | 2013-05-04 | 2013-07-05 | 0000-00-00
3  | 35       | 2013-02-01 | 0000-00-00 | 0000-00-00 | 0000-00-00

My question is what query could I use to find all the courses with a date less than or equal to today in one of the four fields ordered by date descending. So for my database above the query would give me:

id  | courseID | date
---------------------------
1   | 10       | 2013-02-05
3   | 35       | 2013-02-01
1   | 10       | 2013-01-01

Many thanks for your help.

  • 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-18T15:57:26+00:00Added an answer on June 18, 2026 at 3:57 pm

    If you can’t normalize your table, you could use a UNION query, like this:

    SELECT id, courseID, date1 date
    FROM yourtable
    WHERE date1>'0000-00-00' and date1<=curdate()
    UNION
    SELECT id, courseID, date2 date
    FROM yourtable
    WHERE date2>'0000-00-00' and date2<=curdate()
    UNION
    SELECT id, courseID, date3 date
    FROM yourtable
    WHERE date3>'0000-00-00' and date3<=curdate()
    UNION
    SELECT id, courseID, date4 date
    FROM yourtable
    WHERE date4>'0000-00-00' and date4<=curdate()
    ORDER BY date
    

    See fiddle here.

    Since I am using UNION, all duplicates will be removed. If you don’t want to remove duplicates, you could use UNION ALL instead.

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

Sidebar

Related Questions

I have a table in my MySQL database with, say, following fields: id, client,
Let's say i have a mysql database table 'article' with the following fields: id
In my mysql database I have the following information in a page name field.
I have the following MySQL database: |deal_name|price|shop|expiration_date - - - - - - -
I have a MySQL innodb database at 1.9GB, showed by following command. SELECT table_schema
I have the following two tables in my mysql database. Table Name: groups id
I have the following task: there are a simple table from mysql database: <html>
I have the following serialized PHP array stored in a mySQL database: a:2:{i:2070;s:4:0.00;i:1901;s:4:1.00;} Now,
I have following query and data saved in a MySQL database with a timestamp
I have three mysql table from same database Db1. Three tables have following columns.

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.