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 > Using Fetch in subselect

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-07, 08:15
Camfa Camfa is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
Using Fetch in subselect

Hi all!

I want to get data from 2 different tables.

They have the following structure:

http://img337.imageshack.us/img337/2...tuctureqy8.jpg
or see attachement

The result i want to become is the following. I want all the lines in SROBTR that the same INREFX number as the first line in the SROKBA table (BTREFX).

So i did the following:

Code:
SELECT *
FROM SROBTR
WHERE INREFX = (SELECT BTREFX FROM SROKBA FETCH FIRST 1 ROWS ONLY);
Unfortunately, i receive the following error:

Code:
SQL STATE: 42601
Vendor Code: -199
Keyword FETCH not expected. Valid tokens: ) UNION EXCEPT. Cause.....: The keyword FETCH was not expected here. A syntax error was detected at keyword FETCH....
I am using DB2 v5.4

Does anyone have a solution for this? Or maybe another workaround to get the correct result?

Thanks in advance,
Andrew
Attached Thumbnails
Using Fetch in subselect-dbstucture.jpg  
Reply With Quote
  #2 (permalink)  
Old 12-10-07, 09:13
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Which version of DB2 are you running on which platform?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 12-10-07, 10:26
Camfa Camfa is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
Ok, nevermind, I already found a solution. Instead of using a FETCH, I'm using a MIN() in my subselect, because all the values are unique.

Thanks anyway for reading

Andrew
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