Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Statement Inner Join + Others...So join within a join?
    primarykey
    data
    text
    <p>I have the following SQL statement where I am adding game inventory and ordered inventory and then selecting the games that have that total inventory below the reorder point. The only problem is that I also want to select the game inventory below the reorder point that does not have any ordered inventory. I tried messing with the Having line where ItemIDs don't match, but no luck. Here is the current working code.</p> <p>What I have:</p> <pre><code>SELECT tblGames.ItemID, tblGames.Title, ABS(tblGames.Inventory + Sum(tblSupplyOrders.Inventory)) AS UpdatedInventory FROM tblGames INNER JOIN tblSupplyOrders ON tblGames.ItemID=tblSupplyOrders.ItemID Group By tblGames.ItemID, tblGames.Title, tblGames.Inventory, tblGames.ReorderPoint Having ABS(tblGames.Inventory + Sum(tblSupplyOrders.Inventory)) &lt; tblGames.ReorderPoint </code></pre> <p>What I also want to display with it:</p> <pre><code>SELECT tblGames.ItemID, tblGames.Title, tblGames.Inventory FROM tblGames INNER JOIN tblSupplyOrders ON tblGames.ItemID=tblSupplyOrders.ItemID Group By tblGames.ItemID, tblGames.Title, tblGames.Inventory, tblGames.ReorderPoint Having tblGames.Inventory &lt; tblGames.ReorderPoint </code></pre> <p><strong><em>...where there is no tblSupplyOrders.ItemID</em></strong></p> <p>Thanks in advance!</p> <h2>Update Requested</h2> <p>tblGames includes:</p> <ul> <li>ItemID int, auto PK</li> <li>Title varchar(100)</li> <li>Inventory int,</li> <li>ReorderPoint int</li> </ul> <p>tblSupplyOrders includes:</p> <ul> <li>SupplyOrder int, auto PK</li> <li>ItemID int, FK to tblGames</li> <li>Inventory int</li> </ul> <p>So if:</p> <ul> <li>tblGames/tblSupplyOrders.ItemID = The Same #</li> <li>tblGames.Inventory = 2</li> <li>tblSupplyOrders.Inventory = 3</li> <li>tblGames.ReorderPoint = 6</li> <li>Output will include this game.</li> <li>The problem: It won't detect this game if there is no matching ItemID in tblSupplyOrders.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload