Join two tables and filter them with where clause

后端 未结 2 1413
悲&欢浪女
悲&欢浪女 2021-01-29 10:23

I have problem getting the SQL output I want.

I have two tables like this:

tblOrder

ID    User    Status
1      1         0
2           


        
相关标签:
2条回答
  • 2021-01-29 10:38

    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!

    0 讨论(0)
  • 2021-01-29 10:49

    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
    
    0 讨论(0)
提交回复
热议问题