In my system, I have clients. Clients have programs. I want to display a list of clients, showing their most recent active (if it exists) program.
Thus, we have some
Try this order by clause ...
ORDER BY client.id, CASE WHEN program.close_date = 0 THEN 0 ELSE 1 END, program.close_date DESC