1

I have to update a column in a very, very large table. So performance is a big issue.

The question is the similar to this one, but only for Sybase Adaptive Server Enterprise (ASE 12.5.4) plus I need to do an update on the retrieved rows. Is there a way to do it without a self join like in the top voted answer for Oracle?

This was the first attempt with a join, but it is by orders to slow for the table it is intended for:

UPDATE table SET flag = 1
FROM table AS a1
LEFT OUTER JOIN table AS a2
ON (a1.groupId = a2.groupId AND a1.id < a2.id)
WHERE a2.groupId IS NULL
and a1.somename in ('x', 'y')
Community
  • 1
  • 1
Daniel
  • 11
  • 1
  • 3

1 Answers1

1

Would...

UPDATE table AS t1 SET flag = 1
    WHERE t1.somename IN ('x', 'y') AND
          t1.id = (SELECT MAX (t2.id)
                    FROM table t2
                    WHERE t2.groupId = t1.groupId);

be any help?

Brian Hooper
  • 21,544
  • 24
  • 88
  • 139