UPDATE T_EMAIL
SET
  TOROLT = 'T'
  ,LASTCHANGED = GETDATE()
  ,MODIFIER = 0
  ,SERIAL = SERIAL + 1
WHERE
  C_GONDVISELOID IS NOT NULL
  AND C_ALAPERTELMEZETT = 'F'
  AND TOROLT = 'F'
;

WITH CTE AS (
  SELECT
     *
    ,ROW_NUMBER() OVER(PARTITION BY C_GONDVISELOID, C_TANEVID ORDER BY LASTCHANGED DESC) AS RN
  FROM T_EMAIL
  WHERE
    TOROLT = 'F'
    AND C_GONDVISELOID IS NOT NULL
)
UPDATE CTE
SET
   TOROLT = 'T'
  ,C_ALAPERTELMEZETT = 'F'
  ,LASTCHANGED = GETDATE()
  ,MODIFIER = 0
  ,SERIAL = SERIAL + 1
WHERE RN > 1
;

WITH CTE AS (
  SELECT
     *
    ,ROW_NUMBER() OVER(PARTITION BY C_GONDVISELOID, C_TANEVID ORDER BY LASTCHANGED DESC) AS RN
  FROM T_EMAIL
  WHERE
    TOROLT = 'F'
    AND C_GONDVISELOID IS NOT NULL
)
UPDATE CTE
SET
   C_ALAPERTELMEZETT = 'T'
  ,LASTCHANGED = GETDATE()
  ,MODIFIER = 0
  ,SERIAL = SERIAL + 1
WHERE 
  RN = 1
  AND C_ALAPERTELMEZETT = 'F'
;