-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
CREATE TABLE sprog_system_front (
    id INTEGER NOT NULL,
    sprog_id INTEGER,
    felt1 VARCHAR(50),
    felt2 VARCHAR(50),
    felt3 VARCHAR(50),
    PRIMARY KEY(id)
);

INSERT INTO sprog_system_front VALUES(1,1,'tekst1','tekst2','tekst3');
INSERT INTO sprog_system_front VALUES(2,2,'tekst4',NULL,'tekst6');
INSERT INTO sprog_system_front VALUES(3,3,'tekst7','tekst8','tekst9');
INSERT INTO sprog_system_front VALUES(4,4,NULL,'tekst11','tekst12');

SELECT *
FROM sprog_system_front;

SELECT t.id,t.sprog_id,COALESCE(t.felt1,tdefault.felt1) AS felt1,COALESCE(t.felt2,tdefault.felt2) AS felt2,COALESCE(t.felt3,tdefault.felt3) AS felt3
FROM sprog_system_front t,(SELECT * FROM sprog_system_front WHERE sprog_id=1) tdefault;

DROP TABLE sprog_system_front;
