【MySQL】複数のテーブルを対象にした left join

頑張ったので、メモ

select c.name, a.url, k.word, r.created, r.rank from companies as c left join ((key as k left join ali_spec as a on k.id = a.keyword_id) left join records as r on k.id = r.keyword_id) on c.id = k.company_id;

今回は4つのテーブルを結合した。

複数のテーブルに対する left join は
((table1 + table2) + table3)
のようになる。
数学っぽい・・・。

それに対しての left join は
table0 + ((table1 + table2) + table3)
数学っぽい・・・。

数式で考えると簡単かも・・・。

【追記】
select * from tb0 left join tb1 on tb0.id = tb1.id left join tb2 on tb0.id = tb2.id;
のように結合することもできる。
sql 難しいな・・・。