1. A method of optimizing a query performed by a computer to retrieve data from a database, comprising: (a) determining whether a query includes a self join that is transitively derived through table expressions having UNION operators; and (b) simplifying the query to eliminate the table expressions and to reduce the query to an equivalent query over tables, when the query includes the self join that is transitively derived through the table expressions having the UNION operators.