SELECT DISTINCT(a.id) as article_id, title, alias, id_page, file, af.id as file_id
FROM (
SELECT
id_item,
min(rank) as min_rank
FROM pm_article_file
GROUP BY id_item
) as mins
INNER JOIN pm_article_file as af ON mins.id_item = af.id_item AND mins.min_rank = af.rank
INNER JOIN pm_article as a ON mins.id_item = a.id
WHERE a.home = 1 AND a.checked = 1 AND af.checked = 1 AND a.lang = 2
ORDER BY a.add_date DESC LIMIT 4
[Err] 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 ') as min_rank FROM pm_article_file GROUP BY id_item ) as' at line 5
how could I fix that syntax error?