简体   繁体   English

从两个表生成 SQL 查询 (MS Access)

[英]Generate SQL Query From Two Tables (MS Access)

I have two tables in my in my database我的数据库中有两个表

Interim Storage Orders Table临时存储订单表

|ID|Date Product Was Made|RecipeID|  Recipe Name  |ProductID|Product Name|
 1   November 10th, 2015    1       100LB S Batch    1         Saltbread
 2   November 10th, 2015    2       100LB B Batch    2         Bran Fruit

Recipes Table食谱表

 |RecipeID|   Recipe Name   |ProductID|Product Name|ItemID| Item |Amount
     1       100LB S Batch       1      Saltbread     213   Salt   100
     1       100LB S Batch       1      Saltbread     56    Sugar   60
     2       100LB B Batch       2      Bran Fruit    213   Salt    34
     2       100LB B Batch       2      Bran Fruit    56    Sugar   12

What I would like to achieve is a Query Table displaying我想实现的是一个查询表显示

ItemID | Item |      Date Used      | Amount | ProductID | Product Name |
  213    Salt   November 10th, 2015    100         1         Saltbread
  56     Sugar  November 10th, 2015     60         1         Saltbread
  213    Salt   November 10th, 2015     34         2         Bran Fruit
  56     Sugar  November 10th, 2015     12         2         Bran Fruit

what would be the SQL code to achive this result in MS Access在 MS Access 中实现此结果的 SQL 代码是什么

This would be your query:这将是您的查询:

--Iso is Interim Storage Orders Table
--Rec is Recipes Table
--As stated in query

SELECT Rec.ItemID, Rec.Item, Iso.DateProductWasMade, 
Rec.Amount, Iso.ProductID, Iso.ProductName
FROM Recipes AS Rec
INNER JOIN InterimStorageOrders AS Iso ON Rec.ProductID = Iso.ProductID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM