EDIT To simplify this further.
Let’s take a look at this structure:
Table1: idProduct (int) | Name (varchar)
Table2: idDay (int) | idProduct (int) | date_start(datetime) | date_end (datetime)
idProduct is a common column in both tables. Table two contains data similar to this:
0, 2, 11/22/2012, 11/22/2012
1, 2, 11/23/2012, 11/23/2012
2, 2, 11/24/2012, 11/24/2012
3, 2, 00/00/0000, 11/25/2012
4, 2, 11/25/2012, 00/00/0000
Note that date_start, date_end or both may be all zeroes, in which case this upper or lower limit is considered unbound/unlimited.
In the above case I would like to select idProduct with ID 2 ONLY if today’s date is between the period – earliest date in date_start and latest date in date_end.
If date_start is 00/00/0000 always return the product BUT if date_end is in the future. The reverse applies for date_end being all zeroes and date_start being set. If both columns are zeroes return the product.
I don’t see the “LEFT JOIN” requirement in your question : just in your title. So
or if you want to check if product has at least one start_date smaller than today (or 0) and at least one end_date bigger than today(or 0), even if start_date and end_date don’t share the same idDay :
It will take :
min start_date = 0 and max end_date = 0
min start_date = 0 and max end_date >= today
min start_date <= today and max end_date =0
min start_date <= today and max end_date >= today