How MySQL Uses Internal Temporary Tables
How MySQL Uses Internal Temporary Tables ,
->Temporary tables can be created under conditions such as these:
->If there is an ORDER BY clause and a different GROUP BY clause, or if the ORDER BY or GROUP BY contains columns from tables other than the first table in the join queue, a temporary table is created.
->DISTINCT combined with ORDER BY may require a temporary table.
->If you use the SQL_SMALL_RESULT option, MySQL uses an in-memory temporary table, unless the query also contains elements (described later) that require on-disk storage.