Update 2 lines with When

You can do it with EXISTS:

UPDATE t1
SET t1.Status = CASE
  WHEN EXISTS (SELECT 1 FROM tablename t2 WHERE t2.Nam = t1.Nam AND t2.Val2 > t2.Val1) THEN 'OK'
  ELSE 'False'
END
FROM tablename t1

See the demo.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top