my MySQL database has over 1 million records and is growing more and more. I have a value ‘aid’ there which is sometimes available multiple times. I want to count aid.
I tried
SELECT COUNT ( DISTINCT (value) ) AS somevalue
FROM table
which worked but now there are so many values that it takes longer than max_exec_time. I also tried the same with GROUP BY without success.
Is there any way to run this query fast? Or are there any other solutions?
Make value a index! Counting a index is much faster then processing records in a table.