If I use the SELECT DISTINCT query on a table with 100 rows where 98 entries of the table are identical and the other 2 are identical, would it still go through all 100 rows just to return the 2 distinct results?
Is there a way to use indexing/keys etc so that instead of going through all 100 rows, it would instead go through 2 rows?
####EDIT#####
so I added this index:
KEY `column` (`column`(1)),
but then when I do
EXPLAIN SELECT DISTINCT column FROM tablename
it’s still saying that it’s going through all rows rather than just distinct ones
Creating an index on the column or set of columns being queried with
DISTINCTwill speed up the query. Rather than looking through every row it will use the two entries in the index. With only 100 rows though, the difference may not even be detectable.