MySQL中的JOIN子句主要用于將兩個或多個表中的數據連接起來,并返回滿足特定條件的結果。這對于從多個相關表中提取數據非常有用。以下是MySQL JOIN的一些基本用法:
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name
UNION
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
SELECT column_name(s) FROM table1 CROSS JOIN table2;
注意:在使用JOIN時,請確保正確指定連接條件,以避免返回錯誤或意外的結果。