Fixed sql query for search