(SELECT
f.product_id, `file`.file_id, `file`.filename AS filename, CONCAT('https://domain.ru/f/', `file`.file_id, '/', `file`.filename) AS file_url
FROM `file`
INNER JOIN
(
SELECT product.product_id, p_files.file_id
FROM product
INNER JOIN
(
SELECT object_has_file.object_id, object_has_file.file_id
FROM object_has_file
LEFT JOIN file_has_file_category
ON object_has_file.file_id = file_has_file_category.file_id
WHERE object_has_file.object_type_id = 1 AND object_has_file.descendibility_id IN (1,3) AND file_has_file_category.file_category_id IS NULL
) AS p_files
ON product.product_id = p_files.object_id AND product.is_deleted = 0 AND product.product_category_id IN (236408)
UNION
SELECT product.product_id, p_files.file_id
FROM product
INNER JOIN product_category
ON product.product_category_id = product_category.product_category_id
INNER JOIN
(
SELECT object_has_file.object_id, object_has_file.file_id
FROM object_has_file
LEFT JOIN file_has_file_category
ON object_has_file.file_id = file_has_file_category.file_id
WHERE object_has_file.object_type_id = 2 AND object_has_file.descendibility_id IN (2,3) AND file_has_file_category.file_category_id IS NULL
) AS p_files
ON product_category.parent_id = p_files.object_id AND product.is_deleted = 0 AND product.product_category_id IN (236408)
) AS f
ON f.file_id = `file`.file_id AND `file`.is_published = 1 AND (`file`.end_date > NOW() OR `file`.end_date IS NULL))
EXCEPT
(SELECT
f.product_id, `file`.file_id, `file`.filename AS filename, CONCAT('https://domain.ru/f/', `file`.file_id, '/', `file`.filename) AS file_url
FROM `file`
INNER JOIN
(
SELECT product.product_id, p_files.file_id
FROM product
INNER JOIN
(
SELECT object_has_file.object_id, object_has_file.file_id
FROM object_has_file
LEFT JOIN file_has_file_category
ON object_has_file.file_id = file_has_file_category.file_id
WHERE object_has_file.object_type_id = 1 AND object_has_file.descendibility_id IN (1,3) AND file_has_file_category.file_category_id IS NULL
) AS p_files
ON product.product_id = p_files.object_id AND product.is_deleted = 0 AND product.product_category_id IN (236408)
UNION
SELECT product.product_id, p_files.file_id
FROM product
INNER JOIN
(
SELECT object_has_file.object_id, object_has_file.file_id
FROM object_has_file
LEFT JOIN file_has_file_category
ON object_has_file.file_id = file_has_file_category.file_id
WHERE object_has_file.object_type_id = 2 AND object_has_file.descendibility_id IN (2,3) AND file_has_file_category.file_category_id IS NULL
) AS p_files
ON product.product_category_id = p_files.object_id AND product.is_deleted = 0 AND product.product_category_id IN (236408)
UNION
SELECT product.product_id, p_files.file_id
FROM product
INNER JOIN product_category
ON product.product_category_id = product_category.product_category_id
INNER JOIN
(
SELECT object_has_file.object_id, object_has_file.file_id
FROM object_has_file
LEFT JOIN file_has_file_category
ON object_has_file.file_id = file_has_file_category.file_id
WHERE object_has_file.object_type_id = 2 AND object_has_file.descendibility_id IN (2,3) AND file_has_file_category.file_category_id IS NULL
) AS p_files
ON product_category.parent_id = p_files.object_id AND product.is_deleted = 0 AND product.product_category_id IN (236408)
) AS f
ON f.file_id = `file`.file_id AND `file`.is_published = 1 AND (`file`.end_date > NOW() OR `file`.end_date IS NULL)
where file.mime like 'image%')
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXCEPT (SELECT f.product_id, `file`.file_id, `file`.filename AS ' at line 70