I want to execute another SELECT based on column data. For example, I have a table http://sqlfiddle.com/#!2/093a2 where I want to compare start_date and end_date only if use_schedule = 1. Otherwise, select all the data. (Another choice) Basically I want to compare only the start and end date, if only use_schedule is 1, and if use_schedule is 0, then select the rest of the data.
An example would be something like
select id, name from table where use_schedule = 0 else select id, name, start_date from table where use_schedule = 0 and current_date >= start_date.
Basically I have data where the schedule is on, and then look at the beginning and end of the date. Because if the schedule is not included, it makes no sense to study the dates. Just select the data. With a schedule enabled, I want to be more selective when choosing scheduled data.
I am trying to find out if the MySQL CASE or IF statements work, but cannot do this. How to run this selection?
Thanks.
source share