Last record of Join table

后端 未结 7 1014
忘了有多久
忘了有多久 2021-01-06 16:05

I am lookign for the correct SQL code to join 2 tables and show only the last record of the details table.

I have a DB with 2 tables,

Deals 
   Deal         


        
7条回答
  •  日久生厌
    2021-01-06 16:52

    What about this query.

    select * from Deals 
    left join DealComments on Deals.DealID = DealComments.DealID and DealComments.CommentTime = (SELECT CommentTime  FROM DealComments WHERE DealComments.DealID = Deals.DealID ORDER BY CommentTime DESC limit 1)
    

提交回复
热议问题