fixing search sql query