Unknown table 'function' in where clause