many-to-many with double select and where clause doesn't allow search field

I need to include a where clause in a SQL statement with a double select field to configure a many-to-many field as follows:
select idacciones, dsacciones
from acciones
WHERE
idempresa={idempresa}
ORDER BY fecha desc

the problem is that way I can’t activate any search field. I get this error:

With search,a linked table can not use a local variable in select. field = acciones.

any idea?

Are you sure the error is coming from the sql of the double select?

The error refers to field = acciones but no where in your sql you use a field acciones (except for the tablename).