MySQL Forums
Forum List  »  Newbie

Select unique vals in column. Anything faster than SELECT DISTINCT?
Posted by: Blah Duh
Date: July 22, 2010 03:21PM

I have large table (185 million records, growing at 1-2 million per month). I have already indexed most of the fields, but that isn't helping me with selecting unique values from a column. The query is pretty basic:

SELECT DISTINCT(`FILE_ID`) FROM tableName;

"FILE_ID" is an int(11) value, and is indexed. Doing a "SELECT count(`FILE_ID`) FROM tableName" completes in under a second.

The problem is that the "DISTINCT" query takes AGES to complete. I don't actually know how long, because I stopped the query after 25 minutes. Is there a faster way for me to get unique values from a column?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.