For simplicity, we did not optimize the query and did not deal with indexes since this is not a production environment.