;WITH ls AS (
SELECT a.*, b.*
FROM public.tables as a LEFT JOIN tables_log as b on a.id = b.id
)
SELECT * FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY time DESC) AS r
FROM ls
) sub
WHERE r = 1
;WITH ls AS (
SELECT a.*, b.*
FROM public.tables as a LEFT JOIN tables_log as b on a.id = b.id
)
SELECT * FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY time DESC) AS r
FROM ls
) sub
WHERE r = 1