<blockquote>
<p>Pulling your hair out because of errors like so: "ERROR 1248 (42000): Every derived table must have its own alias" ?<br><br>If you have several complicated unioned queries that you want to use in a sub query try encapsulating them like so:<br><br>SELECT col1,col2,col3 FROM<br>(<br><br> SELECT * FROM<br> (<br> SELECT col1,col2,col3 FROM myTable WHERE … etc.<br> ) AS DerivedTable1<br><br>UNION<br><br> SELECT * FROM<br> (<br> SELECT col1,col2,col3 FROM myTable WHERE … etc.<br> ) AS DerivedTable2<br><br>) AS MainTable GROUP BY… HAVING… ORDER BY… LIMIT… etc.<br><br>This method of aliasing will add years to your life by providing the unique distinction required of derived tables in sub queries without having to spend a bunch of time trying to alias every table and field while continuing to get "derived table" errors. Thanks goes to David Fells for helping me keep some of my hair over this one!<br><br>Have fun.<br></p>
</blockquote>