IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Difference between order by column name and order by(nos


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Parasakthi
Currently Banned

New User


Joined: 14 Feb 2008
Posts: 1
Location: Bangalore

PostPosted: Fri Feb 22, 2008 10:49 am
Reply with quote

Hi all,

Where we have to use order by 1,2 clause?

What is the difference between order by column name and order by(nos)..
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 275
Location: Bang,iflex

PostPosted: Fri Feb 22, 2008 1:15 pm
Reply with quote

Hi......

GROUP BY class concentrates on fetching data row wise, where as ORDER BY specifies fetching the data in column wise.

consider one example query for analysis.

SELECT DEPT,COUNT(*) FROM STAFF GROUP BY DEPT HAVING MAX(COMM)>5000 ORDER BY 2 DESC

Here query considering on the 2nd column that is DEPT and the maximum of commission and grouped together after satisfying HAVING condition.

If u want to operate on the particular column or particular group u can give ORDER BY 2(2nd column) DESC or GROUP BY 3(3rd row) ASC(default)
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Feb 22, 2008 6:42 pm
Reply with quote

Did you even read the O/P? They didn't ask anything about GROUP BY.

Parasakthi: The syntax of ORDER BY allows you to refer to columns either by name or by position. Both are valid references and give them same end result.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Feb 22, 2008 6:57 pm
Reply with quote

But of course the danger in using numbers is that they must be adjusted if someone later modifies the SELECT list, and names are more meangful.

However, if you have a bunch of UNIONs, the col names most likely differ, so I think you must use numbers.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Fri Feb 22, 2008 7:24 pm
Reply with quote

but sometimes you need to use NUMBERS becouse the field you need to order by is not a column but a function, for example, column3+column4-column5...
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Fri Feb 22, 2008 7:50 pm
Reply with quote

Can't you give a name to a SELECT expression?
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Fri Feb 22, 2008 8:52 pm
Reply with quote

I cannot test it now BUT I think you cannot use that name in order by... can anyone try it?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Rotate partition-logical & physic... DB2 0
No new posts first column truncated in search result IBM Tools 13
Search our Forums:

Back to Top