The bug is in your code and the error already tells you what it is. You are missing an alias for the first select item in your subquery. Use from (select numeredContact numeredContact, row_number()...