Junção de dados no SQL
Maham Faisal Khan
Senior Content Developer, DataCamp
FULL JOIN
combina uma LEFT JOIN
e uma RIGHT JOIN
FULL JOIN
com base (ON
) no campo id
SELECT left_table.id AS L_id,
right_table.id AS R_id,
left_table.val AS L_val,
right_table.val AS R_val
FROM left_table
FULL JOIN right_table
USING (id);
Observação: a palavra-chave FULL OUTER JOIN
também pode ser usada.
SELECT p1.country AS country, prime_minister, president
SELECT p1.country AS country, prime_minister, president
FROM prime_ministers AS p1
SELECT p1.country AS country, prime_minister, president
FROM prime_ministers AS p1
FULL JOIN presidents AS p2
SELECT p1.country AS country, prime_minister, president
FROM prime_ministers AS p1
FULL JOIN presidents AS p2
ON p1.country = p2.country
LIMIT 10;
| country | prime_minister | president |
|----------------|------------------|-------------------------|
| Egypt | Mostafa Madbouly | Abdel Fattah el-Sisi |
| Portugal | Luís Montenegro | Marcelo Rebelo de Sousa |
| Pakistan | Shehbaz Sharif | Asif Ali Zardari |
| United Kingdom | Keir Starmer | null |
| USA | null | Joe Biden |
| Uruguay | null | Luis Lacalle Pou |
| Chile | null | Gabriel Boric |
| India | Narendra Modi | Droupadi Murmu |
| Norway | Jonas Gahr Støre | null |
| Brunei | Hassanal Bolkiah | null |
Junção de dados no SQL