SELECT
f.folder_id,
owner_id,
folder_name,
created_at
FROM
folders f
LEFT JOIN permissions p ON f.folder_id = p.folder_id
WHERE
parent_folder_id = $1
AND (p.user_id = $2 OR f.owner_id = $2)