Improved last_date SQL query, getting the MAX date from several tables.