INNER JOIN (內部連接)
INNER JOIN (內部連接) 為等值連接,必需指定等值連接的條件,而查詢結果只會返回符合連接條件的資料。
1 | SELECT table_column1, table_column2... |
Example
1 | SELECT customers.C_Id,customers.Name,customers.Address,customers.Phone,customers.Salary,orders.Order_No,orders.Product,orders.Product,orders.Quantity |
NATURAL JOIN
1 | SELECT table_column1, table_column2... |
Example
1 | SELECT customers.C_Id,customers.Name,customers.Address,customers.Phone,customers.Salary,orders.Order_No,orders.Product,orders.Product,orders.Quantity FROM `customers` NATURAL JOIN `orders`; |
*MySQL 目前還不支援 INTERSECT。
LEFT JOIN 會返回左側資料表中所有資料列,就算沒有符合連接條件,而右側資料表中如果沒有匹配的資料值就會顯示為 NULL。
ORDER BY 查詢用法 (Example)
從下面的 employees 資料表中取出所有員工的資料並依職稱來作排序 (即字母順序):
LEFT JOIN 會返回左側資料表中所有資料列,就算沒有符合連接條件,而右側資料表中如果沒有匹配的資料值就會顯示為 NULL。
### SELECT 語法 (SQL SELECT Syntax)