select program.*, mcourses.entry as mce, mcourses.name, mcourses.description, mcourses.duration from program, mcourses where ((program.prog_start_date > curdate() and program.online_prog=0) or (program.online_prog=1 and program.prog_end_date > curdate())) and program.publish=1 and program.did_not_run=0 and program.tipstate= and mcourses.entry=program.course order by program.prog_start_date, mcourses.name