modified all_events sql query.