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.gr开发者_运维技巧oupId IS NULL
and a1.somename in ('x', 'y')
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?
精彩评论