473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subselect Row Restrictions

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_tabl e
WHERE conditions are met
FETCH FIRST 1 ROWS ONLY
)

Thanks.

Sep 8 '06 #1
2 2916
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_tabl e
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_tabl e(id int)
INSERT INTO SESSION.some_ot her_table VALUES (1), (2)
INSERT INTO SESSION.some_ta ble (SELECT id FROM SESSION.some_ot her_table
FETCH FIRST 1 ROWS ONLY)
SELECT * FROM SESSION.some_ta ble
DROP TABLE SESSION.some_ot her_table
DROP TABLE SESSION.some_ta ble
COMMIT

What was the error that you received?

B.

Sep 8 '06 #2
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1738
by: limbert | last post by:
------=_NextPart_000_0001_01C34D7B.DFBF53C0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, =20 I was reading the manual and it said that the subselect is only
6
16312
by: Greg Stark | last post by:
So I have a query in which some of the select values are subqueries. The subqueries are aggregates so I don't want to turn this into a join, it would become too complex and postgres would have trouble optimizing things. So my question is, is there some way to have a subselect return multiple columns and break those out in the outer query? ...
3
7183
by: Neil Zanella | last post by:
Hello, I would like to ask the about the following... PostgreSQL allows tables resulting from subselects to be renamed with an optional AS keyword whereas Oracle 9 will report an error whenever a table is renamed with the AS keyword. Furthermore, in PostgreSQL when the result of a subselect is referenced in an outer select it is required...
7
3741
by: Najib Abi Fadel | last post by:
Is postgres going to support in a future release the use of SUBSELECT in a CHECK expression ?? Thx
4
2736
by: James | last post by:
I have a performance problem with the following query and variations on the subselect. The EXISTS version of the first example will complete in ~10 minutes. The NOT logic in both the examples makes them both keep running long enough that a communications error is the only result returned so far. This is a federated view computer ~160 k...
4
7548
by: dtwalter | last post by:
Is it possible to ORDER BY a SubSelect? I don't see why it wouldn't be, but I'm having some trouble. Hopefully it's just a simple error in syntax and somebody can tell me. Here's what I'm trying to do... I've got two tables: Table1: TestData Filename Bird FileB Blue FileA Circle FileC
1
1709
by: Marco Lazzeri | last post by:
I'd like to reference values returned by a subselect in the same SELECT query. Example: SELECT id, ( SELECT COUNT(*) FROM second ) AS value_to_reference, ( value_to_reference + 1 ) AS value_that_uses_referenced_one FROM first;
4
5471
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why this would be happening, we would appreciate feedback. We have tested on 7.3.4, 7.3.6 and 7.4.1 and all exhibit the same behavior. Test case one...
6
5005
by: Sebastien | last post by:
I have the following statement which I run successfully in... 1 hour 10 minutes. SELECT a.tsgicd as ACCT_ID, a.tsa5cd as SEC_ID, CASE WHEN (SUBSTRING(a.tsgicd, 6, 1) = 'R' or SUBSTRING(a.tsgicd, 6, 1) = 'Y' or SUBSTRING(a.tsgicd, 6, 1) = '0'
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.