According to tips from MySQL performance wiki:
Don’t use DISTINCT when you have or could use GROUP BY.
Can somebody post example of queries where GROUP BY can be used instead of DISTINCT?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you know that two columns from your result are always directly related then it’s slower to do this:
than this:
because in the second case it only has to compare the id, but in the first case it has to compare both fields. This is a MySQL specific trick. It won’t work with other databases.