Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
why a DB2 column used in ORDER BY is mandatory in SELECT too

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions
Author Message
mf_user
Currently Banned

Active User


Joined: 05 Jan 2006
Posts: 76

PostPosted: Mon Nov 26, 2007 6:43 pm    Post subject: why a DB2 column used in ORDER BY is mandatory in SELECT too
Reply with quote

Hi,

I was just going through a program and found that a SELECT query with ORDER BY. This is an embedded query in a COBOL-DB2 program.

This particular query has a SELECT statment with four columns from DB2 table and the ORDER BY is having a different column name (not from the four column names of SELECT). Is it possible?

Can we have such a query? I read that if a column has to be used in ORDER BY then it must be mentioned in SELECT also.

Please explain.

Thanks.
Back to top
View user's profile Send private message
References
PostPosted: Mon Nov 26, 2007 6:43 pm    Post subject: Re: why a DB2 column used in ORDER BY is mandatory in SELECT too Reply with quote

muthuvel

Active User


Joined: 29 Nov 2005
Posts: 178
Location: Chennai

PostPosted: Mon Nov 26, 2007 7:17 pm    Post subject: Reply to: why a DB2 column used in ORDER BY is mandatory in
Reply with quote

Quote:
Can we have such a query? I read that if a column has to be used in ORDER BY then it must be mentioned in SELECT also.


Not So.It is enought that if the columns are present in the table which are given in the SQL


This is what the manual says for your question

Quote:
If the column name is not found in the result table, it must unambiguously identify a column of a table, view, or nested table expression in the FROM clause of the subselect.


Correct me if i am wrong.
Back to top
View user's profile Send private message
mf_user
Currently Banned

Active User


Joined: 05 Jan 2006
Posts: 76

PostPosted: Mon Nov 26, 2007 9:03 pm    Post subject: Thx
Reply with quote

Sounds interesting. Any more thoughts on this?
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 862
Location: Virginia, USA

PostPosted: Mon Nov 26, 2007 9:21 pm    Post subject: Re: Thx
Reply with quote

mf_user wrote:
Sounds interesting. Any more thoughts on this?

I think it used to be required but not anymore, not sure when the change was made.
Back to top
View user's profile Send private message
Anuj D.

Senior Member


Joined: 22 Apr 2006
Posts: 1264
Location: Mumbai, India

PostPosted: Mon Dec 03, 2007 6:15 pm    Post subject:
Reply with quote

Hi,

Yeah is should be this way only...
Quote:
I think it used to be required but not anymore, not sure when the change was made.

When one writes a query then he is creating a 'view' of 'that' table for which the query is written..so even by intuition one would like to "order" that 'view' on the basis of some column in that 'view' ..not on some arbitrary column from the base table.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Senior Member


Joined: 20 Oct 2006
Posts: 1067
Location: germany

PostPosted: Mon Dec 03, 2007 8:18 pm    Post subject:
Reply with quote

Quote:

Yeah is should be this way only...


so even though the column is not necessary, you want it there anyway? That is not efficient. The proper way would be to document the procedure so that the results are anticipated.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions All times are GMT + 6 Hours
Page 1 of 1