MySQL Forums
Forum List  »  Performance

Re: Distinct or Group by which is faster
Posted by: Peter Brawley
Date: February 22, 2016 12:33PM

Those queries are not logically equivalent.

The first will return exactly one row for each combination of id,name,age values found.

The second will return exactly one row for each value of id found, along with name and age values selected arbitrarily from those found for each id.

The logical equivalent to select distinct id,name,age from ... would be select id,name,age from ... group by id,name,age.

Which is faster depends on what else is in the query. In some cases, MySQL might use execute select Distinct a,b,c as Group By a,b,c.

Options: ReplyQuote


Subject
Views
Written By
Posted
1774
February 22, 2016 08:50AM
Re: Distinct or Group by which is faster
918
February 22, 2016 12:33PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.