Daten in SQL verbinden (JOIN)
Maham Faisal Khan
Senior Content Developer, DataCamp
SELECT * FROM left_table INNER JOIN right_table ON left_table.id = right_table.id
INNER JOIN another_table ON left_table.id = another_table.id;
Hinweis. Je nach Anwendungsfall kann in der ON
-Klausel entweder left_table
oder right_table
verwendet werden.
prime_minister_terms
aus unserer Datenbank der StaatsoberhäupterSELECT p1.country, p1.continent,
president, prime_minister
FROM prime_ministers as p1
INNER JOIN presidents as p2
USING(country);
| country | continent | president | prime_minister |
| -------- | ------------- | ----------------------- | ---------------- |
| Egypt | Africa | Abdel Fattah el-Sisi | Mostafa Madbouly |
| Portugal | Europe | Marcelo Rebelo de Sousa | Luís Montenegro |
| Pakistan | Asia | Asif Ali Zardari | Shehbaz Sharif |
| India | Asia | Droupadi Murmu | Narendra Modi |
-- SQL query for chaining inner joins SELECT p1.country, p1.continent, president, prime_minister, pm_start FROM prime_ministers as p1 INNER JOIN presidents as p2 USING(country)
INNER JOIN prime_minister_terms as p3 USING(prime_minister);
SELECT *
FROM left_table
INNER JOIN right_table
ON left_table.id = right_table.id;
INNER JOIN
mittels ON
auf das Feld id
SELECT *
FROM left_table
INNER JOIN right_table
ON left_table.id = right_table.id
AND left_table.date = right_table.date;
INNER JOIN
mittels ON
auf das Feld id
UND (AND) date
Daten in SQL verbinden (JOIN)