Isso soa como um caso de uso clássico para o
EXISTS
operador:SELECT *
FROM mytable a
WHERE EXISTS (SELECT 1
FROM mytable b
WHERE a.foreignkey = b.foreignkey
AND trainer IS NOT NULL
AND trainer <> 'FREE'
EDITAR:
Se você quer apenas a distinta
foreignkey
s:SELECT DISTINCT foreignkey
FROM mytable a
WHERE EXISTS (SELECT 1
FROM mytable b
WHERE a.foreignkey = b.foreignkey
AND trainer IS NOT NULL
AND trainer <> 'FREE'