Aamir
Aamir

Reputation: 758

how to replace distinct with something faster in mysql query?

I have a query like this -

SELECT COUNT(DISTINCT c.y_no) 
FROM xyz c 
WHERE c.xdate>='2013-09-01';

Because of DISTINCT, my query taking too much time. This query scanning around 150 million records. I already have index on xdate. Please suggest me something faster.

Thank you.

Upvotes: 1

Views: 609

Answers (1)

Saic Siquot
Saic Siquot

Reputation: 6513

Well, a compound index on xdate, y_nro will help too much

Upvotes: 1

Related Questions