-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE TABLE noget (
    superid INTEGER,
    id INTEGER PRIMARY KEY,
    dato VARCHAR(6),
    active TINYINT
)
GO
INSERT INTO noget VALUES(1, 1, '10 jan', 0)
GO
INSERT INTO noget VALUES(1, 2, '20 jan', 0)
GO
INSERT INTO noget VALUES(1, 3, '30 jan', 0)
GO
INSERT INTO noget VALUES(2, 4, '10 jan', 0)
GO
INSERT INTO noget VALUES(2, 5, '8 jan', 0)
GO
INSERT INTO noget VALUES(2, 6, '6 jan', 0)
GO
SELECT * FROM noget
GO
UPDATE noget SET active=1 WHERE id IN (SELECT id FROM noget t1 WHERE dato=(SELECT MAX(dato) FROM noget t2 WHERE t2.superid = t1.superid))
GO
SELECT * FROM noget
GO
DROP TABLE noget
GO
