Fix sql query for search