1. An apparatus comprising: at least one processor; a memory coupled to the at least one processor; a query residing in the memory that includes an outer SELECT statement with a DISTINCT specifier and an inner SELECT statement; and a query optimizer residing in the memory and executed by the at least one processor, wherein the query optimizer analyzes the query to determine if the query can be optimized and generates from the query a new query that includes a reformulated SELECT statement with the DISTINCT added to the inner SELECT statement in the query.