You need to use wfelems.WFD_ID because WFD_ID alone isn’t recognized inside the subquery. At that level, SQL doesn’t know which table the column belongs to. By adding the alias wfelems (which i think refers to the V_WFElements view in the main query), SQL can correctly link both tables. So the