How to limit results of a LEFT JOIN

后端 未结 4 1972
南旧
南旧 2020-12-17 09:10

Take the case of two tables: tbl_product and tbl_transaction.
tbl_product lists product details including names and ids while

4条回答
  •  臣服心动
    2020-12-17 09:46

    I found way to make LEFT JOIN with subquery, sorted and limited, its works on RDS Amazon, MariaDB v10.2

    LEFT JOIN activities last_activity ON last_activity.id = ( 
         SELECT id FROM activities 
         WHERE contester_id = contesters.id AND `type` IN ({$last_activity_types}) 
         ORDER BY id DESC LIMIT 1 
    )
    

    All others ways to make LEFT JOIN with GROUPING and SORTING didn't works for me. This example is working exception.

提交回复
热议问题