changed the sql query for viewEvents