-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
CREATE TABLE garbage (
    id INTEGER NOT NULL,
    PRIMARY KEY(id)
)
GO
INSERT INTO garbage VALUES(1);
INSERT INTO garbage VALUES(2);
INSERT INTO garbage VALUES(3);
INSERT INTO garbage VALUES(4);
INSERT INTO garbage VALUES(5);
GO

SELECT * FROM garbage;
GO

DELETE FROM garbage
FROM garbage g JOIN (SELECT id,ROW_NUMBER() OVER (ORDER BY id) AS rn FROM garbage) x ON g.id=x.id
WHERE x.rn<3
GO

SELECT * FROM garbage;
GO

DROP TABLE garbage
GO

