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
Could you please tell me the difference between using distinct and group by in the query?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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 :-)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.