Prepare for your Next Interview
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?...
|
|||
|
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 |
| Sponsored Links |
|
|||
|
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. |
| The Following User Says Thank You to Barbie For This Useful Post: | ||
|
|||
|
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. |
|
|||
|
Quote:
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. ![]() |
|
|||
|
Re: difference b/w "group by" and "order by" ?
Quote:
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. |
|
|||
|
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.
|
|
|||
|
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....
|
|
|||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |