Display each DISTINCT Field Value only once using loop

前端 未结 3 1059
夕颜
夕颜 2021-01-26 04:36
SELECT listTitle, listLength, listCmt, listDt, mBCFName, mBCLName, moAmt, moDtOff
FROM User U, Listing L, Merchant M, MerchantOffer MO
WHERE U.uID = L.uID
and L.listID =         


        
3条回答
  •  忘了有多久
    2021-01-26 05:33

    It sounds to me like you want to print listTitle as a group heading above the relevant comments.

    One way to do it would be to keep track of listTitle of the previous row, and then only print it if there's a difference with the current row. Of course, you'd have to make sure your result set is ordered by listTitle.

    Another way would be to have one query that gets all data for that group heading, then another query that gets the contents of the group.

    It is also probably possible to do it in the query, but that will be tricky since you want the first record with that listTitle to have a value for listTitle and the others to have null - until the next listTitle that's different.

提交回复
热议问题