tags:

views:

77

answers:

2

tell some big, diff between order by and group by,

like sort columns data=>order by

group it by similar data used for aggregation , order by could be used inside the grouped items ,

please Tell 5 diff

+1  A: 

group by groups data by one or more columns, and order by orders the data by one or more columns? i don't really get the question?

using group by is similar to select distinct in the aspect that only unique values for the given values will be returned. furthermore you can use aggregate functions to calculate e.g. the sum for each group.

what do you want to hear? tell me five differences between apples and oranges?

knittl
+1  A: 

The order by clause is used to order your data set. For example,

select *
    from customers
    order by customer_id asc

will give you a list of customers in order of customer id from lowest to highest.

The group by clause is used to aggregate your data. For example,

select customer_id, sum(sale_price), max(sale_price)
    from customers
    group by customer_id
    order by customer_id asc

will give you each customer along with their total sales and maximum sale, again ordered by customer id.

In other words, grouping allows you to combine multiple rows from the database into a single output row, based on some criteria, and select functions of those fields not involved in the grouping (minimum, maximum, total, average and so on).

paxdiablo