If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Nested Table expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-04, 08:15
vidyaraok vidyaraok is offline
Registered User
 
Join Date: Aug 2004
Posts: 15
Nested Table expression

hello,

i am firing a query:

SELECT DBA_NM TITLE,ROW_NUMBER() OVER() ROWNUM
FROM DW05.FMIS_CLNT_ORGN
WHERE UPPER(CORP_ID) LIKE RTRIM(UPPER('WPPG00'))||'%'
AND DBA_NM NOT LIKE 'ZZZ%' order by 1;

and getting the result:

TITLE ROWNUM
----------------------------------- --------------------
J. Walter Thompson 1
Ogilvy & Mather 2
Ogilvy Public Relations 3

Next i want to select the row with rownum 1, so i am writing query :


SELECT TEMP.TITLE
FROM
(SELECT DBA_NM TITLE,ROW_NUMBER() OVER() ROWNUM
FROM DW05.FMIS_CLNT_ORGN
WHERE UPPER(CORP_ID) LIKE RTRIM(UPPER('WPPG00'))||'%'
AND DBA_NM NOT LIKE 'ZZZ%' order by 1
) AS TEMP
WHERE TEMP.ROWNUM=1;

and result is:

TITLE
-----------------------------------
Ogilvy & Mather

But i am expectig to get J. Walter Thompson as a result.

can any one explain why it is like this and how do i get the expected result?

thanks
Reply With Quote
  #2 (permalink)  
Old 10-06-04, 08:42
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
SELECT TEMP.TITLE
FROM
(SELECT DBA_NM TITLE,ROW_NUMBER() OVER(order by DBA_NM) ROWNUM
FROM DW05.FMIS_CLNT_ORGN
WHERE UPPER(CORP_ID) LIKE RTRIM(UPPER('WPPG00'))||'%'
AND DBA_NM NOT LIKE 'ZZZ%'
) AS TEMP
WHERE TEMP.ROWNUM=1;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On