ProductID 11 is currently out of stock.
It has a quntity of 0
I need to get the orders that have productid = 11
and only other products that are in stock.
Here is what I'm using, but it is returning products that have a quantity of 0.
select *
from Orders a
inner join LineItems b
on a.OrderID = b.OrderID
and b.ProductID = 11
where a.OrderStatusID = 3
and a.GatewaySuccessful = 1 and not exists
(select 1
from Products p
where b.ProductID = p.ProductID
and p.QuantityInStock > 0)
select *
from Orders a
inner join LineItems b on a.OrderID = b.OrderID
inner join Products p on b.ProductID = p.ProductID
where a.OrderStatusID = 3
and b.ProductID = 11
and a.GatewaySuccessful = 1
and p.QuantityInStock > 0