-- 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 a (aid INTEGER NOT NULL, atxt VARCHAR(50), PRIMARY KEY(aid));
CREATE TABLE b (bid INTEGER NOT NULL, aid INTEGER, btxt VARCHAR(50), PRIMARY KEY(bid));

INSERT INTO a VALUES(1,'A');
INSERT INTO a VALUES(2,'B');

INSERT INTO b VALUES(1,1,'X');
INSERT INTO b VALUES(2,1,'Y');
INSERT INTO b VALUES(3,2,'Z');
INSERT INTO b VALUES(4,2,'W');

SELECT a.aid,a.atxt,b.bid,b.btxt FROM a JOIN b ON a.aid=b.aid;

SELECT a.aid,a.atxt,b.bid,b.btxt FROM a JOIN b ON a.aid=b.aid GROUP BY a.aid;

SELECT a.aid,MIN(a.atxt),MIN(b.bid),MIN(b.btxt) FROM a JOIN b ON a.aid=b.aid GROUP BY a.aid;

SELECT a.aid,MAX(a.atxt),MAX(b.bid),MAX(b.btxt) FROM a JOIN b ON a.aid=b.aid GROUP BY a.aid;

DROP TABLE a;
DROP TABLE b;
