I have problem getting the SQL output I want.
I have two tables like this:
tblOrder
ID User Status
1 1 0
2
The main problem I found that I had done was write O.ID = OI.ID
instead of O.ID = OI.OrderID
. Thats why I only got one row per ID.
I should have seen that but I only thought of other problems. Thanks for the help!
Like Coder of Code mentioned you should JOIN
Both the table, apply O.Status = 0
using the WHERE
clause and then use ORDER BY
to order the results in the required way using ASC
or DESC
based on the ascending or descending order like below. Its better to go with List<string> as it has methods to search, sort, and manipulate lists.
SELECT OI.OrderID, O.User, OI.Product, OI.Quantity
FROM tblOrder O
INNER JOIN tblOrderItem OI ON O.ID = OI.OrderID
WHERE O.Status = 0
ORDER BY OI.OrderID ASC, OI.Product ASC