DISTINCT Optimization. DISTINCT combined with ORDER BY needs a temporary table in many cases. Because DISTINCT may use GROUP BY, learn how MySQL works with columns in ORDER BY or HAVING clauses that are not part of the selected columns.
DISTINCT is converted to a GROUP BY on all columns and it will be combined with the ORDER BY clause.
SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;