首先,我没有SQL开发人员。因此,我需要帮助从以下三个表中检索一些信息。
我希望names
,order date
和product code
为那些订购产品的人product code
= 401.1201
如何编写SQL查询以从表中检索信息?
dbo.tblMaterial
dbo.tblMaterialOrder
dbo.tblMaterialOrderItem
我试过......
Select * From dbo.tblMaterialOrder mo Where Exists (Select MembershipUserId From
dbo.tblMaterialOrderItem Where dbo.tblMaterialOrderItem.Material_MaterialId =
(Select MaterialId From dbo.tblMaterial Where (ProductCode = '401.1201')))
和
Select * from dbo.tblMaterialOrder, dbo.tblMaterialOrderItem, dbo.tblMaterial
Where
dbo.tblMaterialOrderItem.Material_MaterialId = '248' And
dbo.tblMaterialOrderItem.MaterialOrder_MaterialOrderId =
dbo.tblMaterialOrder.MaterialOrderId
没有成功。
答案 0 :(得分:0)
这样的事情:
SELECT
tblMaterial.Name,
tblMaterialOrder.OrderDate,
tblMaterial.ProductCode
FROM
tblMaterial
JOIN tblMaterialOrderItem
ON tblMaterial.MaterialId=tblMaterialOrderItem.Material_MaterialId
JOIN tblMaterialOrder
ON tblMaterialOrder.MaterialOrderId=tblMaterialOrderItem.MaterialOrder_MaterialOrderId
WHERE
tblMaterial.ProductCode='401.1201'
答案 1 :(得分:0)
SELECT
M.NAME
,M.MATERIALID
,O.ORDERDATE
FROM MATERIAL M
LEFT JOIN ORDERITEM OI ON M.MATERIALID = OI.MATERIAL_MATERIALID
LEFT JOIN ORDER O ON OI.MaterialOrder_MaterialOrderId = O.MaterialOrderId
WHERE M.MATERIALID = '401.1201'
答案 2 :(得分:0)
试试这个未经测试的Skript:
select a.name, b.orderdate, a.productcode
from tblMaterial a left outer join tblMaterialOrderItem b
on a.MaterialId = b.Material_MaterialId
left outer join tblMaterialOrder c
on c.MaterialOrder_MaterialOrderId = b.MaterialOrderId
where a.productcode = '401.1201'