﻿UPDATE T_EMAIL
  SET C_ALAPERTELMEZETT = 'T'
WHERE ID IN (
	SELECT MIN(e.ID) 
	FROM T_EMAIL e
	INNER JOIN T_TANEV tv ON tv.ID = e.C_TANEVID AND tv.C_AKTIV = 'T' AND tv.TOROLT = 'F'
	WHERE e.C_GONDVISELOID IS NULL
		AND e.TOROLT = 'F'
	GROUP BY C_FELHASZNALOID
	HAVING COUNT(1) = 1
)
	AND C_ALAPERTELMEZETT = 'F'

