I need to do update User
table records that have the max endDate replaced for a user with the value of null. A null will indicate that the specific user record is the current record. To explain: this table tracks temporal changes for each user. Here is what I am doing right now. It works but the CONCAT could be intensive. Is there another way that would be faster then this? Cursors are definitely slower. Tried that already.
db is mysql
USE CUSTOMER;
CREATE TEMPORARY TABLE IF NOT EXISTS keyValuePairs
SELECT `user`, MAX(endDate)as mEndDate FROM `User` GROUP BY `user`;
UPDATE `User` SET `endDate` = NULL
WHERE CONCAT(`user`, `endDate`) IN
(SELECT CONCAT(`user`, `mEndDate`) FROM keyValuePairs);