- The SQL language allows users to express queries that have nested subqueries in them. Optimization of nested queries has received considerable attention over the last few years. Executing a query after unnesting it leads to lesser processing compared to executing it in the nested form itself. Kim's algorithm for unnesting nested queries has a COUNT bug for Join Aggregate type queries. Richard A. Ganski and U. Dayal gave general strategies to avoid the COUNT bug. M. Muralikrishna modified Kim's algorithm so that it avoids the COUNT bug. Apart from this, he proposed an integrated algorithm for generating query plans for a given input query. In this paper, we have given a solution for implementing the Kim's modified algorithm of unnesting nested queries and this also avoids the COUNT bug convincingly. We observed that the integrated algorithm holds flaws and modifications for correcting these flaws have been proposed in this paper. All existing and proposed query plans ha...