SELECT
    EXISTS (
        SELECT
            file_name as name
        FROM
            files
        WHERE
            folder_id = $1
            AND file_name = $2
        UNION
        SELECT
            folder_name as name
        FROM
            folders
        WHERE
            parent_folder_id = $1
            AND folder_name = $2
    )