-- 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 eks1 (
    fpk INTEGER NOT NULL PRIMARY KEY,
    fval VARCHAR(25)
)
GO
INSERT INTO eks1 VALUES (1, '-')
GO
INSERT INTO eks1 VALUES (2, '-')
GO
INSERT INTO eks1 VALUES (3, '-')
GO
INSERT INTO eks1 VALUES (4, '-')
GO
INSERT INTO eks1 VALUES (5, '+')
GO
INSERT INTO eks1 VALUES (6, '+')
GO
INSERT INTO eks1 VALUES (7, '+')
GO
INSERT INTO eks1 VALUES (8, '+')
GO
INSERT INTO eks1 VALUES (9, '+')
GO
INSERT INTO eks1 VALUES (10, '+')
GO
INSERT INTO eks1 VALUES (11, '-')
GO
INSERT INTO eks1 VALUES (12, '-')
GO
INSERT INTO eks1 VALUES (13, '-')
GO
INSERT INTO eks1 VALUES (14, '-')
GO
INSERT INTO eks1 VALUES (15, '-')
GO
SELECT TOP 5 * FROM eks1 WHERE fpk NOT IN (SELECT TOP 5 fpk FROM eks1 ORDER BY fpk) ORDER BY fpk
GO
DROP TABLE eks1
GO
CREATE TABLE eks2 (
    fpk INTEGER NOT NULL IDENTITY(1,1) PRIMARY KEY,
    fnonpk INTEGER,
    fval VARCHAR(25)
)
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (1, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (1, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (1, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (1, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (2, '?')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (3, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (3, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (3, '-')
GO
INSERT INTO eks2 (fnonpk, fval) VALUES (3, '-')
GO
SELECT TOP 5 * FROM eks2 WHERE fnonpk NOT IN (SELECT TOP 5 fnonpk FROM eks2 ORDER BY fnonpk) ORDER BY fnonpk
GO
SELECT * FROM (SELECT TOP 5 * FROM (SELECT TOP 10 * FROM eks2 ORDER BY fnonpk) x ORDER BY fnonpk DESC) y ORDER BY fnonpk
GO
DROP TABLE eks2
GO
