Link to home
Start Free TrialLog in
Avatar of hasozduru
hasozduru

asked on

Difference between distinct and group by

Hi

Could you please tell me the difference between using distinct and group by in the query?

Thanks
Avatar of kupra1
kupra1

You can go here to learn and know about it:
http://dev.mysql.com/doc/mysql/en/index.html

In a nutshell, distinct will return you distnct data i.e. no duplicate records for the field for which you have applied the word distinct data whereas the "Group By" is wider. It returns one record per group i.e based on the field on which you have applied the "Group By" clause.
SOLUTION
Avatar of peyox
peyox
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi..

that ditinct functionality u can achieve through group by..see the following example..

select distinct col1,col2 from Table..

The above select statment can be re-written as

select col1,col2 from Table group by col1,col2

Hope this helps



Avatar of Renante Entera
Hi hasozduru!

For your reference, visit the following sites :

Group by - http://dev.mysql.com/doc/mysql/en/group-by-functions-and-modifiers.html
Selecting Particular Columns - http://dev.mysql.com/doc/mysql/en/selecting-columns.html
How MySQL Optimizes DISTINCT - http://dev.mysql.com/doc/mysql/en/distinct-optimization.html

Hope this helps you.


Goodluck!
eNTRANCE2002 :-)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial