-- Collection of code snippets by Arne Vajhøj 
-- (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
CREATE TABLE myorder (
    orderid INTEGER NOT NULL,
    customer VARCHAR(50),
    PRIMARY KEY (orderid)
);
CREATE TABLE orderline (
    orderlineid INTEGER NOT NULL,
    orderid INTEGER NOT NULL,
    itemname VARCHAR(50),
    itemprice DECIMAL(9,2) NOT NULL,
    quantity INTEGER NOT NULL,
    PRIMARY KEY(orderlineid)
);     

INSERT INTO myorder VALUES(1, 'A A');
INSERT INTO myorder VALUES(2, 'B B');
INSERT INTO orderline VALUES(1, 1, 'A good DB book', 19.95, 1);
INSERT INTO orderline VALUES(2, 2, 'ASUS MB', 249.00, 1);
INSERT INTO orderline VALUES(3, 2, 'i5 CPU', 299.00, 1);
INSERT INTO orderline VALUES(4, 2, '4 GB kit', 29.00, 4);

SELECT customer, itemname, itemprice, quantity
FROM myorder JOIN orderline ON myorder.orderid = orderline.orderid;
