/* Selected fields from the 'user' and 'oauth_app' tables */ /* Create a 'key' from the 'userId' and 'app.name' for grouping purposes */ SELECT u.username, app.name AS appname, concat(token."userId", app.name) as key FROM public.oauth_token token /* Join to the 'user' table */ INNER JOIN public.user u ON token."userId" = u.id /* Join to the 'oauth_app' table */ INNER JOIN public.oauth_app app ON app.id = token."appId"