我有一個數據庫來表示零售物品。有些項目有多個掃描碼,但本質上是相同的項目,即。他們的名字,成本和零售總是一樣的。爲了模擬此,the database has the following structure:SQL JOIN獲取庫存物品和替代物品的清單
Inventory_Table
INV_PK | INV_ScanCode | INV_Name | INV_Cost | INV_Retail
1 | 00| Muffins | 0.15 | 0.30
2 | 000987654321 | Cookie | 0.25 | 0.50
3 | 00| Cake | 0.45 | 0.90
Alternates_Table
ALT_PK | INV_FK | ALT_ScanCode
1 | 2 | 000999888777
2 | 2 | 000666555444
3 | 2 | 000333222111
現在說我要在數據庫中的所有掃描代碼列表,我將如何連接表得到以下的輸出:
ScanCode | Name | Cost | Retail
00| Muffins | 0.15 | 0.30
000987654321 | Cookie | 0.25 | 0.50
000999888777 | Cookie | 0.25 | 0.50
000666555444 | Cookie | 0.25 | 0.50
000333222111 | Cookie | 0.25 | 0.50
00| Cake | 0.45 | 0.90