Geeks Talk

Prepare for your Next Interview




difference b/w "group by" and "order by" ?

This is a discussion on difference b/w "group by" and "order by" ? within the SQL forums, part of the Databases category; What is difference b/w "group by" and "order by", SQL query?...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-27-2007
Moderator
 
Join Date: Sep 2006
Location: Delhi (India)
Posts: 866
Thanks: 12
Thanked 81 Times in 65 Posts
jainbrijesh is on a distinguished road
difference b/w "group by" and "order by" ?

What is difference b/w "group by" and "order by", SQL query?
__________________
Brijesh Jain
brijesh.tester@yahoo.co.in
http://softwaretestingexpertise.blogspot.com
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-30-2007
Expert Member
 
Join Date: Dec 2006
Location: Chennai
Posts: 197
Thanks: 2
Thanked 16 Times in 14 Posts
Barbie is on a distinguished road
Re: difference b/w "group by" and "order by" ?

GROUP BY colllects values in multiple records by the group by column.
ORDER BY simply sorts in ascending or descending order.
Reply With Quote
The Following User Says Thank You to Barbie For This Useful Post:
  #3 (permalink)  
Old 05-02-2007
Junior Member
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
rishamjeet is on a distinguished road
Re: difference b/w "group by" and "order by" ?

OREDER BY sort your result set into asc or desc order, asc in the default.
whereas The GROUP BY keyword is used when we are selecting multiple columns from a table (or tables) and at least one arithmetic operator appears in the SELECT statement. When that happens, we need to GROUP BY all the other selected columns, i.e., all columns except the one(s) operated on by the arithmetic operator.
Reply With Quote
  #4 (permalink)  
Old 06-12-2007
Junior Member
 
Join Date: Jun 2007
Location: INDIA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ibarnali is on a distinguished road
Re: difference b/w "group by" and "order by" ?

fetched records can be sorted out by order by clause.
record set can be summarized by group by clause.
Reply With Quote
  #5 (permalink)  
Old 06-14-2007
Junior Member
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rsrpns is on a distinguished road
Cool Re: difference b/w "group by" and "order by" ?

Quote:
Originally Posted by jainbrijesh View Post
What is difference b/w "group by" and "order by", SQL query?
hi
here group by clause we use group by clause mainly when we want to use some agregate functions like sum which return agregate of all columns value every time they r called & with out the group by clause it was not possible to find the sum for each individual gruop of columns values .basically group by clause is use to work on group .
and order by clause is use to sort particular column alfabatically or numerically wht ever value columns has in decending or accending order.
Reply With Quote
  #6 (permalink)  
Old 06-14-2007
Junior Member
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rsrpns is on a distinguished road
Re: difference b/w "group by" and "order by" ?

Quote:
Originally Posted by rsrpns View Post
hi
here group by clause we use group by clause mainly when we want to use some agregate functions like sum which return agregate of all columns value every time they r called & with out the group by clause it was not possible to find the sum for each individual gruop of columns values .basically group by clause is use to work on group .
and order by clause is use to sort particular column alfabatically or numerically wht ever value columns has in decending or accending order.
hi
here group by clause we use group by clause mainly when we want to use some agregate functions like sum which return agregate of all columns value every time they r called & with out the group by clause it was not possible to find the sum for each individual gruop of columns values .basically group by clause is use to work on group .
and order by clause is use to sort particular column alfabatically or numerically wht ever value columns has in decending or accending order.
Reply With Quote
  #7 (permalink)  
Old 06-19-2007
Junior Member
 
Join Date: Dec 2006
Location: INDIA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rajneeshbajwa is on a distinguished road
Re: difference b/w "group by" and "order by" ?

Group by is a way to sub-total your results, or perform some other "aggregate" function on them. Example: select department, sum(salary) from tblemployee group by department; will give you salary totals by department, whereas the sum statement by itself would just give you the grand total of all salaries in tblemployee. Order by is a way to sort your results - it does not affect what shows up in your resultset, only what order it is displayed. Example: select * from tblemployee order by lastname; will give you all tblemployee data, in order of last name. If you want the results in descending (reversed) order, simply add desc to the end of the clause: order by lastname desc; by default rsults are displayed in ascending order.
Reply With Quote
  #8 (permalink)  
Old 06-19-2007
Junior Member
 
Join Date: May 2007
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
ashokkumar_vnr is on a distinguished road
Smile Re: difference b/w "group by" and "order by" ?

thanks buddy.. thanks
Reply With Quote
  #9 (permalink)  
Old 06-19-2007
Contributing Member
 
Join Date: May 2007
Location: bangalore
Posts: 65
Thanks: 3
Thanked 8 Times in 6 Posts
hari.nattuva is on a distinguished road
Re: difference b/w "group by" and "order by" ?

'group by' is used to get the data from table by grouping one or more columns when it come to the order by used to sorting the column data either ascending or decending order....
Reply With Quote
  #10 (permalink)  
Old 07-07-2007
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 125 Times in 112 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: difference b/w "group by" and "order by" ?

group by groups the records as per a single or list of fields.
this is mainly used for displaying aggregate data.

Order by is used for sorting the records.
it can sort either in ascending or descenging order. where ascending is the default sort.

order by only Sorts the resultset in a particular order.
I thas no effect on the actual data while used in a select statment.
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Error "shared memory relm" and oracle is not available Geek_Guest Oracle 1 04-25-2007 09:20 AM
What is warning message 724 "Cast converts default int return type to." Geek_Guest C and C++ 0 04-24-2007 02:16 AM
What is ""developing procedures and scripts (UNIX/Windows/Oracle) spd15 Testing Issues 1 04-04-2007 09:01 AM
Business Objects - parsed failed "ORA-00936: missing expression :-936" JobHelper Data Warehousing 0 02-11-2007 06:06 AM
McAfee launches "TOTAL PROTECTION" Beta Lokesh M Geeks Lounge 0 06-22-2006 08:44 AM


All times are GMT -4. The time now is 12:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved