[SQL] JOINについて

JOINの種類

  • 内部結合(Inner Join)
  • 外部結合(Outer Join)
    • Left Join
    • Right Join
  • クロス結合(Cross Join)

Inner Joinの書き方

SELECT * FROM table1 AS a, table2 AS b WHERE a.id = b.id;

または

SELECT * FROM table1 AS a JOIN table2 AS b ON a.id = b.id;

Outer Joinの書き方

SELECT * FROM table1 AS a LEFT JOIN table2 as b ON a.id = b.id;

Cross Joinの書き方

SELECT * FROM table1, table2;

または

SELECT * FROM table1 CROSS JOIN table2;

コメント

タイトルとURLをコピーしました