Hi,
I have managed to get a nested query to work partly, but i need to somehow add another nest, which i cannot get to work.
To explain more, i wanted to firstly find records that did not exist in another table, to which i used the following
SELECT products.idProduct, products.sku FROM products WHERE NOT EXISTS
(SELECT optionsinventory.idProduct, optionsinventory.inventory FROM optionsInventory WHERE products.idProduct = optionsinventory.idProduct AND optionsinventory.inventory <> 0)
ORDER BY idProduct
This correctly tells me any products that do not have a zero option inventory.
What i want to do now is to display these from the options inventory table, so that it shows me ALL records in options inventory that match the returned idProducts from the above query, but i cannot get this to return the correct results, it is returning id's that are NOT returned in the original results.
I have tried doing this
SELECT optionsInventory.idProduct FROM optionsInventory WHERE EXISTS (SELECT products.idProduct, products.sku FROM products WHERE NOT EXISTS
(SELECT optionsinventory.idProduct, optionsinventory.inventory FROM optionsInventory WHERE products.idProduct = optionsinventory.idProduct AND optionsinventory.inventory <> 0))
ORDER BY idProduct
If i try to use the "As" function i get errors and i think this may be because i am using a web based SQL tool called myLittleAdmin, that may not be able to declare.
Where am I going wrong?
Ultimately, i am trying to get rid of all entries in the optionsInventory table where a value of 0 does not exist for the product id. The problem is the table structure looks like:
idOptInv-------idProduct-------Options-------Inventory
1----------------27----------------10,36----------90
2----------------27----------------12,56----------120
3----------------27----------------84,31----------0
4----------------35----------------20,40----------99
5----------------35----------------19,40----------99
6----------------35----------------25,40----------120
In the above example, 35 would be returned by my query as a product that does not contain any 0 entered inventory, which is correct. I now want to end up returning data from this table, which i would expect to be records 4,5 and 6, so that i can then perform a DELETE query the same to delete these.
I would really appreciate any help.
Thanks
Andrew