来自一个表的多个记录基于来自其他的id

时间:2013-06-05 23:51:37

标签: mysql mysqli

Hello on我正在尝试编写一个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,我想选择多条记录

我使用什么类型的联接,这可能吗?

1 个答案:

答案 0 :(得分: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';