/* Selected fields from the 'notes' and 'user' tables */ /* Select the latest dated note */ SELECT CONCAT(u.username, '@', u.host) AS "User and Host", MAX(n."createdAt") AS "Last Note" FROM public.note n /* Join to the 'user' table */ INNER JOIN public.user u ON n."userId" = u.id /* Join to the 'following' table to limit notes from followees only */ INNER JOIN public.following f ON n."userId" = f."followeeId" GROUP BY CONCAT(u.username, '@', u.host) ORDER BY MAX(n."createdAt") ASC