Difference between Group by and Order by statements

Asked By 0 points N/A Posted on -
qa-featured

In SQL, what is the difference between Group by and Order by statements? Also, I would like to know which statement to choose in a scenario where you need to count something? Can you please define the sub-query method used in Group by statement? ?

SHARE
Answered By 0 points N/A #106503

Difference between Group by and Order by statements

qa-featured

 

Hi Richardine,

Group by used to set of values one or more value.

Order by sets vaues by sorting order.

The most general way to satisfy a GROUP BY clause is to

scan the whole table and create a new temporary table

ORDER BY [col1],[col2],…[coln];

 If two rows will have the same value in col1 it will try to sort them according to col2 and so on.

GROUP BY [col1],[col2],…[coln]; Tells DBMS to group

(Aggregate) results with same value of column col1. You can

Use COUNT(col1), SUM(col1), AVG(col1) with it, sum all values or view average.

E.g. of Sub query of order by:

Select col_names from table_name

order by col_name

Thanking you. Hope this help you.

Related Questions