SQLTeam.com | Weblogs | Forums

Display column1 with column2 having reference with column1

Query : display column1 with column2

SELECT vendeur.nom as "vendeur",vendeur.nom as "Superviseur"
From vendeur
Where numero =  numeroSuperviseur;

Hi everyone , im new here and i encounter some probleme as this one above.
What i want to do is the result looks like this (image)

image

But i don't know why my code is wrong

This is my insert INTO

INSERT INTO `vendeur` VALUES (5,'Judith',NULL);
INSERT INTO `vendeur` VALUES (4,'Pierre',5);

INSERT INTO `vendeur` VALUES (1,'Renaud',4);
INSERT INTO `vendeur` VALUES (2,'Favreau',4);
INSERT INTO `vendeur` VALUES (3,'Hachette',5);

This is my table Vendeur :

CREATE TABLE vendeur(
numero int PRIMARY KEY,
nom VARCHAR (50),
numeroSuperviseur int REFERENCES vendeur(numero)
);

PS : The result is in French.

Thanks for your help :blush:

hi

bonjour Comment ça va j'espère que cela vous aide

create data script

CREATE TABLE #vendeur(
numero int PRIMARY KEY,
nom VARCHAR (50),
numeroSuperviseur int REFERENCES #vendeur(numero)
);

INSERT INTO #vendeur VALUES (5,'Judith',NULL);
INSERT INTO #vendeur VALUES (4,'Pierre',5);
INSERT INTO #vendeur VALUES (1,'Renaud',4);
INSERT INTO #vendeur VALUES (2,'Favreau',4);
INSERT INTO #vendeur VALUES (3,'Hachette',5);

SELECT * FROM #vendeur

SELECT 
    a.nom as 'Vendeur' 
  , b.nom as 'Superviseur' 
FROM  
  #vendeur  a 
    join 
  #vendeur  b   
     on a.numeroSuperviseur = b.numero

image

Ok merci beaucoup