I assume that the array data are in TMP_ARRAY.
You have two sets products and array, You want to retrieve from products only those entires that are in arrays. For this You should use inner join
with proper on clause, next you want to set those results in groups GROUP BY
by column name, as you want to operate only on those results that single group size is bigger then one, the clause having
needs to be added at the end you want to pick from them 'top' id. And here we have a problem what You mean by 'top'? In data base the data don't have any specific order. I assume that is about the largest, other case in this situation mean only one result, so for both cases we select MAX(ID).
In result I came up with something like this
SELECT MAX(ID) FROM PRODUCTS p INNER JOIN TMP_ARRAY t ON t.NAME = p.NAME GROUP BY p.NAME HAVING COUNT(ID) > 1;
But I'm not sure that i have had understand everything correct.