select concat('update  INQUIRIES_TEACHER set OID_PROFESSORSHIP = ', PROFESSORSHIP.OID, ' where OID = ', INQUIRIES_TEACHER.OID, ';') AS "", concat('select ', count(PROFESSORSHIP.OID_PERSON), ';') as total from INQUIRIES_TEACHER inner join INQUIRIES_COURSE on INQUIRIES_COURSE.OID=INQUIRIES_TEACHER.OID_INQUIRIES_COURSE inner join PROFESSORSHIP on PROFESSORSHIP.OID_EXECUTION_COURSE=INQUIRIES_COURSE.OID_EXECUTION_COURSE left join  TEACHER on TEACHER.OID_PERSON=PROFESSORSHIP.OID_PERSON where OID_TEACHER is null and OID_NON_AFFILIATED_TEACHER is null and TEACHER.OID_PERSON is null group by INQUIRIES_TEACHER.OID having total='select 1;';

update INQUIRIES_TEACHER , PROFESSORSHIP, PARTY set INQUIRIES_TEACHER.OID_PROFESSORSHIP =PROFESSORSHIP.OID where INQUIRIES_TEACHER.OID_TEACHER=PARTY.OID_TEACHER and PARTY.OID=PROFESSORSHIP.OID_PERSON;
