Last record of Join table

后端 未结 7 1029
忘了有多久
忘了有多久 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:43

    Try this:

    CREATE VIEW DealsWithLastComment
    AS
       SELECT
           D.*, DC.*
       FROM
           Deals D INNER JOIN DealComments DC
           ON D.DealID = DC.DealID
           GROUP BY D.DealID, DC.CommentTime
           HAVING DC.CommentTime = MAX(DC.CommentTime)
    

提交回复
热议问题