1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| CREATE TABLE T_Personnes (
PersonneId int primary key,
Nom varchar(32) not null,
Prenom varchar(32) not null,
PereId int null,
MereId int null)
INSERT INTO T_Personnes VALUES (1,"DUPOND","Albert",null,null);
INSERT INTO T_Personnes VALUES (2,"DUPOND","Géraldine",null,null);
INSERT INTO T_Personnes VALUES (3,"DUPOND","Riri",1,2);
INSERT INTO T_Personnes VALUES (4,"DUPOND","Fifi",1,2);
CREATE VIEW V_Personnes AS
SELECT P.Nom, P.Prenom, Pere.Nom, Pere.Prenom, Mere.Nom, Mere.Prenom
FROM T_Personnes P
LEFT JOIN T_Personnes Pere ON P.PereId = Pere.PersonneId
LEFT JOIN T_Personnes Mere ON P.MereId = Mere.PersonneId;
SELECT * FROM V_Personnes |
Partager