| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
DISTINCT
DISTINCT combined with ORDER BY will in many cases
need a temporary table.
Note that as DISTINCT may use GROUP BY, you should be aware of
how MySQL works with in fields in ORDER BY or HAVING that
are not part of the selected fields. See section 12.7.3 GROUP BY with Hidden Fields.
When combining LIMIT row_count with DISTINCT, MySQL will stop
as soon as it finds row_count unique rows.
If you don't use columns from all used tables, MySQL will stop the scanning of the not used tables as soon as it has found the first match.
SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a; |
In this case, assuming t1 is used before t2 (check with
EXPLAIN), then MySQL will stop reading from t2 (for that
particular row in t1) when the first row in t2 is found.