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.
If you can’t normalize your table, you could use a UNION query, like this:
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.