﻿UPDATE fb SET
 fb.C_GUID = x.C_GUID
FROM T_FELHASZNALOBELEPES fb
INNER JOIN (
 SELECT C_BEJELENTKEZESINEV , fbsub.C_INTEZMENYID, C_GUID, C_TANEVID FROM T_FELHASZNALOBELEPES fbsub
 INNER JOIN T_TANEV t ON t.ID = fbsub.C_TANEVID AND t.C_AKTIV ='T'
 WHERE fbsub.TOROLT = 'F'
) x ON x.C_BEJELENTKEZESINEV = fb.C_BEJELENTKEZESINEV AND x.C_INTEZMENYID = fb.C_INTEZMENYID
WHERE x.C_TANEVID <> fb.C_TANEVID AND fb.C_GUID <> x.C_GUID
 AND fb.TOROLT = 'F'