【发布时间】:2016-02-18 00:35:56
【问题描述】:
我有三张桌子:
*orders:
-id (PK)
-iduser (FK)
-date
*detail_orders:
-id(PK)
-or_id (FK of id on orders)
-prod_id (FK of id on products)
-price
-quantity
*products:
-id (PK)
-description
有一个orders表,另一个是订单的detail(产品、价格、数量),另一个用于检索订单的描述产品。
我想使用 mysql 从特定 iduser 获取此信息(从 php 检索):
order.id | order.date:
products.description | orders.quantity | orders.price
products.description | orders.quantity | orders.price
products.description | orders.quantity | orders.price
... (etc while there are products on this order)
应该怎么查询?我只有从一个 sql 表中检索数据并且没有从多个表中连接数据的经验。
【问题讨论】:
-
SO 不是辅导服务。您需要自己学习以了解 SQL 连接的基础知识。
-
@Barmar Sory,我忘了写我正在阅读有关 JOIN 并且我理解这个概念,但是当涉及两个以上的表时,我无法做到。
-
显示您的尝试,然后我们可以帮助您了解您做错了什么。 3张表没有显着差异。