-- 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 t1 (
    k INTEGER PRIMARY KEY,
    v VARCHAR(50)
);
CREATE TABLE t2 (
    k INTEGER PRIMARY KEY,
    v VARCHAR(50)
);
INSERT INTO t1 VALUES(1, 'v1.1');
INSERT INTO t1 VALUES(2, 'v1.2');
INSERT INTO t2 VALUES(2, 'v2.1');
INSERT INTO t2 VALUES(3, 'v2.2');
SELECT * FROM t1;
SELECT * FROM t2;
SELECT * FROM t1 JOIN t2 USING(k);
SELECT * FROM t1,t2 WHERE (t1.k=t2.k OR t1.k IS NULL OR t2.k IS NULL);
SELECT * FROM t1 FULL JOIN t2 ON t1.v = t2.v;
SELECT * FROM t1 JOIN t2 ON (t1.k=t2.k OR t1.k IS NULL OR t2.k IS NULL);
SELECT * FROM t1 LEFT JOIN t2 ON t1.k=t2.k
UNION
SELECT * FROM t1 RIGHT JOIN t2 ON t1.k=t2.k WHERE t1.k IS NULL;
DROP TABLE t1;
DROP TABLE t2;
