By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,278 Members | 1,632 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,278 IT Pros & Developers. It's quick & easy.

Subselect Row Restrictions

P: n/a
I am trying to INSERT only the first row returned from a subselect, is
this possible? I'm on DB2 v8 on z/OS.

Non-working Example:

INSERT into some_table (
SELECT id
FROM some_other_table
WHERE conditions are met
FETCH FIRST 1 ROWS ONLY
)

Thanks.

Sep 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Michael wrote:
I am trying to INSERT only the first row returned from a subselect, is
this possible? I'm on DB2 v8 on z/OS.

Non-working Example:

INSERT into some_table (
SELECT id
FROM some_other_table
WHERE conditions are met
FETCH FIRST 1 ROWS ONLY
)

Thanks.
I'm on Solaris, so this may be of no help.

This "worked for me":

DECLARE GLOBAL TEMPORARY TABLE some_table(a int)
DECLARE GLOBAL TEMPORARY TABLE some_other_table(id int)
INSERT INTO SESSION.some_other_table VALUES (1), (2)
INSERT INTO SESSION.some_table (SELECT id FROM SESSION.some_other_table
FETCH FIRST 1 ROWS ONLY)
SELECT * FROM SESSION.some_table
DROP TABLE SESSION.some_other_table
DROP TABLE SESSION.some_table
COMMIT

What was the error that you received?

B.

Sep 8 '06 #2

P: n/a
The error I was receiving was that "FETCH" was an illegal keyword. I
was able to bypass the problem by doing a SELECT MIN(id) since I can
use any of them from the table. Thanks for your suggestion.

Sep 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.