Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:16:45+00:00 2026-05-28T04:16:45+00:00

In DB2 , I need to do a SELECT FROM UPDATE , to put

  • 0

In DB2, I need to do a SELECT FROM UPDATE, to put an update + select in a single transaction.
But I need to make sure to update only one record per transaction.

Familiar with the LIMIT clause from MySQL’s UPDATE option

places a limit on the number of rows that can be updated

I looked for something similar in DB2’s UPDATE reference but without success.

How can something similar be achieved in DB2?


Edit: In my scenario, I have to deliver 1000 coupon codes upon request. I just need to select (any)one that has not been given yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:16:45+00:00Added an answer on May 28, 2026 at 4:16 am

    The question uses some ambiguous terminology that makes it unclear what needs to be accomplished. Fortunately, DB2 offers robust support for a variety of SQL patterns.

    To limit the number of rows that are modified by an UPDATE:

    UPDATE 
    ( SELECT t.column1 FROM someschema.sometable t WHERE ... FETCH FIRST ROW ONLY
    ) 
    SET column1 = 'newvalue';
    

    The UPDATE statement never sees the base table, just the expression that filters it, so you can control which rows are updated.


    To INSERT a limited number of new rows:

    INSERT INTO mktg.offeredcoupons( cust_id, coupon_id, offered_on, expires_on )
    SELECT c.cust_id, 1234, CURRENT TIMESTAMP, CURRENT TIMESTAMP + 30 DAYS 
    FROM mktg.customers c 
    LEFT OUTER JOIN mktg.offered_coupons o
    ON o.cust_id = c.cust_id
    WHERE ....
    AND o.cust_id IS NULL
    FETCH FIRST 1000 ROWS ONLY;
    

    This is how DB2 supports SELECT from an UPDATE, INSERT, or DELETE statement:

    SELECT column1 FROM NEW TABLE (
        UPDATE ( SELECT column1 FROM someschema.sometable 
                 WHERE ... FETCH FIRST ROW ONLY
        ) 
        SET column1 = 'newvalue'
    ) AS x;
    

    The SELECT will return data from only the modified rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pull item quantity from a DB2 database from an aspx page
I'm querying some data from a table in DB2/z which holds hourly data but
I need to make an sql query which tries to update a row by
Problem On a DB2 (version 9.5) the SQL statement SELECT o.Id FROM Table1 o,
I need to copy a table from one database to another. This will be
I need to create a linked server to a DB2 database on a mainframe.
In DB2, you can name a column ORDER and write SQL like SELECT ORDER
I have a db2 database file, but do not have a db2 server. I
What's the DB2 Version of TSQL Print? I've tried Print 'TableName:X' And Select 'X'
I need to test the connection to a db2 database. With oracle databases I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.