MySQL 表连接是指将多个表按照一定的条件关联起来,以获取更丰富的数据信息。MySQL 提供了多种表连接方式,包括内连接、外连接和交叉连接。
SELECT 列名
FROM 表1
INNER JOIN 表2
ON 连接条件;
示例:
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID;
SELECT 列名
FROM 表1
LEFT JOIN 表2
ON 连接条件;
示例:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
SELECT 列名
FROM 表1
RIGHT JOIN 表2
ON 连接条件;
示例:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
RIGHT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
SELECT 列名
FROM 表1
FULL JOIN 表2
ON 连接条件;
示例:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
SELECT 列名
FROM 表1
CROSS JOIN 表2;
示例:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
CROSS JOIN Orders;
以上是 MySQL 表连接的基本用法,可以根据实际需求选择合适的连接方式来获取需要的数据。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站