CodeBlanks Logo Icon CodeBlanks

Üç tablo INNER JOIN

Üç tabloyu zincirleme JOIN ile birleştirmeyi öğrenirsin.

Üç tablo INNER JOIN

Birden çok INNER JOIN art arda zincirlenir. Her JOIN bir ON koşuluyla bir sonraki tabloyu bağlar.

SELECT * FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
INNER JOIN products p ON o.product_id = p.id;

Bu sorgu sipariş, müşteri ve ürün tablolarını birleştirir.

orders o kaynağından tüm sütunlar seçilir. customers c tablosu o.customer_id = c.id koşuluyla yalnızca eşleşen satırlarıyla birleştirilir. products p tablosu o.product_id = p.id koşuluyla yalnızca eşleşen satırlarıyla birleştirilir.

Üç tablo INNER JOIN — ayrıntı

Üç tablo birleştirirken her JOIN ayrı bir ON alır. Sıra okunabilirliği etkiler ama sonucu değiştirmez.

Örneğin orders, customers ve products tablolarını birleştirince her sipariş satırında müşteri adı ve ürün adı yan yana görünür.

Uygulama Üç tablo INNER JOIN

orders, customers ve products tablolarını art arda INNER JOIN ile birleştir.

Başlangıç kodu

query.sql
-- üç tablo birleştir
SELECT * FROM orders o
INNER JOIN customers c ON o.customer_id = c.id

Örnek çözüm

query.sql
SELECT * FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
INNER JOIN products p ON o.product_id = p.id;

Beklenen çıktı

order_id  customer  product
1         Ayşe      Kalem
2         Mehmet    Defter

Soru ve cevaplar

Dersin sorularını cevaplarıyla birlikte inceleyebilirsin. Kendini denemek istersen dersi interaktif olarak çöz.

1 Üç tablo INNER JOIN: kavramları eşleştir

Kavram Anlamı
JOIN birleştir
ON koşul
AS takma
WHERE filtre

2 Üçüncü tabloyu ekle

Soru
SELECT * FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
____ products p ON o.product_id = p.id;
Cevap
SELECT * FROM orders o
INNER JOIN customers c ON o.customer_id = c.id
INNER JOIN products p ON o.product_id = p.id;

Açıklama: INNER JOIN doğru cevap.

3 Üç tablo JOIN'de kaç ON gerekir?

  • Üç
  • İki Doğru cevap
  • Bir
  • Hiç

Açıklama: İki JOIN için iki ON koşulu gerekir.

Orta seviye bölümündeki tüm dersler