MySQL 联表操作是指在查询、增加、删除或修改数据时,涉及两个或多个表的操作。这些操作基于表之间的关系,如一对一、一对多或多对多关系。
SELECT customers.name, orders.order_id
FROM customers
INNER JOIN orders ON customers.customer_id = orders.customer_id;
SELECT customers.name, orders.order_id
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id;
SELECT customers.name, orders.order_id
FROM customers
RIGHT JOIN orders ON customers.customer_id = orders.customer_id;
SELECT customers.name, orders.order_id
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id
UNION
SELECT customers.name, orders.order_id
FROM customers
RIGHT JOIN orders ON customers.customer_id = orders.customer_id;
SELECT customers.name, orders.order_id
FROM customers
CROSS JOIN orders;
通过以上内容,您应该对MySQL联表增删改查有了全面的了解,并能够解决常见的相关问题。
领取专属 10元无门槛券
手把手带您无忧上云