在 SQL 中連接表可以使用 JOIN 關鍵字來實現。常用的連接方式有:
SELECT *
FROM table1
INNER JOIN table2
ON table1.column = table2.column;
SELECT *
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.column = table2.column;
SELECT *
FROM table1
FULL JOIN table2
ON table1.column = table2.column;
還可以使用子查詢或者關聯子查詢來連接表:
SELECT *
FROM table1
WHERE column IN (SELECT column FROM table2);