What is the difference between groupby and orderby?

Showing Answers 1 - 5 of 5 Answers

jayashree a

  • Aug 10th, 2005
 

Group by is used to group set of values based on one or more values. 
Order by is to sort values either in ascending or descending order

  Was this answer useful?  Yes

rkanth18

  • Aug 16th, 2005
 

group by is used when we use aggregate functions on the columns in a query the other columns should be in group by query  
 
eg:  
 
select empno,ename,sum(sal) from emp 
group by empno,ename 
 

  Was this answer useful?  Yes

Venkat80

  • Mar 23rd, 2006
 

Group by is used to get the set of records belongs to the same group.

For Example

Select count(empno),deptno from emp group by  dept

The above statement will display number of records for each department. In the same way we can all agregate functions like sum,avg etc

In group by we can select only the column(s) which are mentioned in group by clause.  In above example we can't select other than deptno and agregate functions of any other columns.

Order by is display the records either in asscending or descending order. What ever the column(s) we are mentioning in the order by clause that column(s) must be exists in selct clause also.  We can select all other columns which are not mentioned in order by clause.

For example

Select empno, ename,deptno from emp order by ename.

ename must be in select clause

we can select other than ename also, but we cant use any aggregate functions here.

  Was this answer useful?  Yes

Neelam Jain

  • Mar 30th, 2006
 

groupby clause is used to group the set of record. groupby clause is used with having clause.whereas order by clause is used to sort th record either acc. or dec. order

  Was this answer useful?  Yes

manu

  • Apr 5th, 2006
 

   Using group by we get set of records for particualar value or content  in column ;

Means it is usde to get group of records for selecting column or grou[

While Order by is used to get sorting list of  records .

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions