WITH MC_MaxValueLength AS (
   SELECT MC.MachineName, MAX(LENGTH(COALESCE(MC.ConfigValue, ''))) AS MaxLength
   FROM VCLib.T_MACHINE_CONFIG AS MC
   GROUP BY MC.MachineName
),
MC_ToKeep AS (
   SELECT DISTINCT ON (MC.MachineName) MC.MachineConfigID
   FROM VCLib.T_MACHINE_CONFIG AS MC
   JOIN MC_MaxValueLength MCV
       ON MC.MachineName = MCV.MachineName
   WHERE LENGTH(COALESCE(MC.ConfigValue, '')) = MCV.MaxLength
)

DELETE FROM VCLib.T_MACHINE_CONFIG
WHERE MachineConfigID NOT IN (SELECT MachineConfigID FROM MC_ToKeep)