Jointure SQL
Clients
Client_id nom
1 Alice
2 Bob
3 Charlie
Commandes
commande_id Client_id monta
nt
101 1 50
102 1 80
103 2 1220
Inner Join
Affiche seulement les lignes qui correspondant dans les deux tableaux
Select nom , montant
From Clients
INNER JOIN Commandes ON Clients.Client_id = Commandes.Client_id
Clients Commandes
Client_id nom commande_id Client_id monta
nt
1 Alice
101 1 50
2 Bob
102 1 80
3 Charlie
103 2 1220
104 4 200
nom montant
Alice 50
Alice 80
Bob 1220
LEFT JOIN
Select nom , montant
From Clients
LEFT JOIN Commandes ON Clients.Client_id = Commandes.Client_id
nom montant
Alice 50
Alice 80
Bob 1220
Charlie Null
Right Join
Select nom , montant, Commande_id
From Commandes
RIGHT JOIN Clients ON Clients.Client_id = Commandes.Client_id
nom montant Commande_id
Alice 50 101
Alice 80 102
Bob 1220 103
Null 200 104
Full outer join
Select nom , montant, Commande_id
From Commandes
FULL OUTER JOIN Clients ON Clients.Client_id = Commandes.Client_id
Client_id nom commande_id Client_id monta
nt
1 Alice
101 1 50
2 Bob
102 1 80
3 Charlie
103 2 1220
5 Daniel
104 4 200
nom montant Commande_id
Alice 50 101
Alice 80 102
Bob 1220 103
Null 200 104
Charlie NULL NULL
Daniel NULL NULL