improve performance of sql query

improve performance of sql query