Results 1 to 11 of 11

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

  1. #1
    Moderator
    Join Date
    Sep 2006
    Answers
    920

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

    What is difference b/w "group by" and "order by", SQL query?

    Regards,
    Brijesh Jain
    ---------------------------------------------------------
    Connect with me on Skype: jainbrijesh
    Google Plus : jainbrijeshji

  2. #2
    Expert Member
    Join Date
    Dec 2006
    Answers
    204

    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.


  3. #3
    Junior Member
    Join Date
    May 2007
    Answers
    11

    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.


  4. #4
    Junior Member
    Join Date
    Jun 2007
    Answers
    1

    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.


  5. #5
    Junior Member
    Join Date
    Jun 2007
    Answers
    2

    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.



  6. #6
    Junior Member
    Join Date
    Jun 2007
    Answers
    2

    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.


  7. #7
    Junior Member
    Join Date
    Dec 2006
    Answers
    2

    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.


  8. #8
    Junior Member
    Join Date
    May 2007
    Answers
    1

    Smile Re: difference b/w "group by" and "order by" ?

    thanks buddy.. thanks


  9. #9
    Contributing Member
    Join Date
    May 2007
    Answers
    60

    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....


  10. #10
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    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.


  11. #11
    Junior Member
    Join Date
    Mar 2009
    Answers
    13

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

    wen we are using any aggregate function in query like MAX,AVG,MIN,COUNT.......... suppose if we are using a avg function then it will calculate avg of some group of vales (more than 1 value)for example we want calculate avg salary of an employee means so many employes are there then u need each employe's avg salary then u have to use group by function on employee name or ID if u are not provide group by then also it wil give avg of total salary amnt that present in colmn ,if u are using group by then it calculate avg salary according to what u have mention at group by clause
    AND in order by which colmn name u have mention that wil display in ascending r descending order according to ur choice


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact