Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Posts
    6

    Unanswered: 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 Attached Thumbnails dbstucture.JPG  

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Which version of DB2 are you running on which platform?
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •