Hay un error: ERROR: column "prd" does not exist LINE 25: WHERE n.idnota =prd ^