Home » Performance » MySQL » DISTINCT vs GROUP BY
DISTINCT vs GROUP BY [message #1319] Sat, 26 May 2007 01:34 Go to previous message
mysql_beginner  is currently offline mysql_beginner
Messages: 5
Registered: May 2007
Junior Member
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();

OR
SELECT userid FROM articles WHERE posted_date BETWEEN '2007-01-01' AND CURDATE() GROUP BY userid;


EXPLAIN is exactly the same for both.

Read Message
Read Message
Read Message
Read Message
Previous Topic:MySQL Optimal Settings
Next Topic:InnoDB DELETE/INSERT vs. UPDATE in transaction
Goto Forum:

  


Current Time: Fri Jul 10 03:31:21 EDT 2009

Total time taken to generate the page: 0.01435 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.