PostgreSQL
 sql >> Base de données >  >> RDS >> PostgreSQL

postgresql joindre 2 tables

SELECT tab1.*, t2.action
FROM  tab1
JOIN (
    SELECT DISTINCT ON (tab1_id) tab1_id
         , first_value(action) OVER (PARTITION BY tab1_id
                                     ORDER BY id DESC) AS action
    FROM   tab2
    ) t2 ON tab1.id = t2.tab1_id

@Mark a déjà mentionné l'alternative LEFT JOIN .