/* Selected fields from the 'session' and 'user' tables */ SELECT s."userId", u.username FROM public.session s /* Join to the 'user' table */ INNER JOIN public.user u ON s."userId" = u.id /* Only return 'active' sessions */ where s.active = TRUE