我很难把头绕在多个查找表上。我有一个中央表,其中包含所有信息,但每列中有 ID:
db_supply (Main supplier information data table)
-----------------------------------------------
| Supplier_ID | Supply_Type_ID | Itm_ID | Stock |
|-----------------------------------------------|
| 1 | 1 | 33 | 3 |
|-----------------------------------------------|
| 2 | 2 | 28 | 1 |
-----------------------------------------------
lookup_supplier
-----------------------------
| Supplier_ID | Supplier_Name |
|-----------------------------|
| 1 | Walter |
|-----------------------------|
| 2 | Jesse |
-----------------------------
lookup_supply_type
-----------------------------------
| Supply_Type_ID | Supply_Type_Name |
|-----------------------------------|
| 1 | Import |
|-----------------------------------|
| 2 | Delivery |
-----------------------------------
lookup_itm
------------------------
| Itm_ID | Itm_Name |
|------------------------|
| 33 | Pickles |
|------------------------|
| 28 | Burger |
------------------------
A query for 'Burger' will output this table:
-----------------------------------------------------
| Supplier_Name | Supply_Type_Name | Itm_Name | Stock |
|-----------------------------------------------------|
| Jesse | Delivery | Burger | 1 |
-----------------------------------------------------
我将如何实现这一目标?到目前为止,我有:
SELECT * FROM db_supply WHERE Itm_ID = (SELECT Itm_ID FROM lookup_itm WHERE Itm_Name = 'Burger')
这会给我db_supply
表格的第二行,其中的 ID 尚未查找。我必须嵌套我的选择来查找多个表吗?这里不知道。