Is there any performance difference between DISTINCT and GROUP BY?
I have a table articles and I want to get unique users who posted the articles. userid has an index. What should I use DISTINCT or GROUP BY? Is there any difference between their performance? I am concerned about the performance.
I need to get only userid from articles. Which one is better?
SELECT DISTINCT userid FROM articles WHERE posted_date BETWEEN ‘2007-01-01’ AND CURDATE();
SELECT userid FROM articles WHERE posted_date BETWEEN ‘2007-01-01’ AND CURDATE() GROUP BY userid;
EXPLAIN is exactly the same for both.