select * from worksheet where id in (select worksheet from "profilesWorksheet" where profile = 'some-id')rpc function. This would work but its annoying to have an extra step. Also currently my postgress setup isnt in version control, so id rather have the query in my node server code not in postgress.