Select rows from one table, join most recent row from other table with one-to-many relationship

前端 未结 1 1923
礼貌的吻别
礼貌的吻别 2020-12-22 01:51

What I would like to do is select a specific set of rows from one table (table A) and join with another table (table B), such that only one record will appear from table A,

相关标签:
1条回答
  • 2020-12-22 02:28

    I think this will help you:

    SELECT A.id, A.col_1, A.col_2, A.datetime_col, A.col_3
    FROM
        (SELECT B.id, B.col_1, B.col_2, C.datetime_col, C.col_3
        FROM tableA B LEFT OUTER JOIN tableB C ON B.id = C.id
        ORDER BY C.datetime_col desc) as A
    GROUP BY A.id
    
    0 讨论(0)
提交回复
热议问题