improved sql query count