Updated the query to be able to get the correct ids