您好,我正在尝试编写一个 mysql 查询,该查询根据另一个表的 id 从一个表中选择多条记录 这是我的查询
SELECT o.total, o.shipping, o.order_date, oc.product_type, oc.quantity, cu.first_name,
cu.last_name, CONCAT(cu.address1, cu.address2) AS address
FROM `orders` AS o
INNER JOIN order_contents as oc ON o.id=oc.order_id
INNER JOIN `customers` AS cu ON o.customer_id=cu.id
WHERE o.customer_id = '217';
在 order_contents 的内部联接上,如果超过 1,我想选择多个记录
我使用什么类型的连接,这可能吗?
最佳答案
只需开始从 order_contents
表中进行选择
SELECT o.total, o.shipping, o.order_date, oc.product_type, oc.quantity, cu.first_name, cu.last_name, CONCAT(cu.address1, cu.address2) AS address
FROM order_contents AS oc
INNER JOIN `orders` as o ON oc.order_id = o.o_id
INNER JOIN `customers` AS cu ON o.customer_id=cu.id
WHERE o.customer_id = '217';
关于mysql - 一个表中的多条记录基于另一表中的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16951697/