I am using MySQL.
I have two tables.
1. Inventory: has rows of Serial Numbers (inventory.SN)
2. Items_Sold: has rows which have two columns of Serial Numbers: Left_SN and Right_SN
I am trying to work on a statement that will see what's left in inventory. I want to display all items in the inventory table that have not been assigned to either Left_SN or Right_SN in a row in Items_Sold.
The above doesn't work, to start with, but even if it did, it excludes the other column: items_sold.Right_SNCode:SELECT DISTINCT inventory.SN FROM inventory WHERE inventory.SN NOT IN (SELECT items_sold.Left_SN FROM items_sold)
... so I then started to do this:
This works great, but it excludes items_sold.Right_SN from the search results.Code:SELECT * FROM inventory LEFT JOIN items_sold ON inventory.SN = items_sold.Left_SN WHERE items_sold.Left_SN IS NULL
Any tips? Thanks.![]()




Reply With Quote