JRockFL
asked on
Query Help
I'm trying to return only 1 row for each order.
An order can have multiple line items.
I want to check each line item to make sure the quantity in stock is greater than 0.
Right now, there is an order that has two lines and both are in stock, but I just want it to return one row.
I pretty much just need a couple columns from the orders table and not the line items table.
SELECT
*
FROM Orders a
INNER JOIN LineItems b
ON a.OrderID = b.OrderID
INNER JOIN Products c ON c.ProductID = b.ProductID
WHERE
c.QuantityInStock > 0
AND
a.OrderStatusID = 1
AND
a.GatewaySuccessful = 1
AND
a.ToBePrinted = 1
An order can have multiple line items.
I want to check each line item to make sure the quantity in stock is greater than 0.
Right now, there is an order that has two lines and both are in stock, but I just want it to return one row.
I pretty much just need a couple columns from the orders table and not the line items table.
SELECT
*
FROM Orders a
INNER JOIN LineItems b
ON a.OrderID = b.OrderID
INNER JOIN Products c ON c.ProductID = b.ProductID
WHERE
c.QuantityInStock > 0
AND
a.OrderStatusID = 1
AND
a.GatewaySuccessful = 1
AND
a.ToBePrinted = 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER