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

  • Home
  • SEARCH
  • 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 8512617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:19:43+00:00 2026-06-11T04:19:43+00:00

So I need to select a value from my table and modify it slightly

  • 0

So I need to select a value from my table and modify it slightly to use as a value in a new row in the same table when inserting. See below:

INSERT INTO reservationbody(
    reservationid,
    driverid,
    tripnumber,
    fromlocation,
    tolocation
)
VALUES(
    1,
    2,
    (
        SELECT
           MAX(tripnumber) + 1
        FROM reservationbody
        WHERE reservationid = 1
    ),
    'here',
    'there'
)

I’m getting the following error:

You can’t specify target table ‘reservationbody’ for update in FROM
clause

I’ve had a look at other questions and have found plenty of questions on this error but they all seem to be about updates and deletes and all require PK values that already exist. None deal with inserting.

Basically what I’m expecting here is that if SELECT MAX(tripnumber) FROM reservationbody where reservationid = 1 returns a value of 4 then the insert should add a new row with a tripnumber value of 5

Can anyone suggest how I can accomplish this?

  • 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-06-11T04:19:45+00:00Added an answer on June 11, 2026 at 4:19 am

    Have you tried (I know you can do this in MS SQL):

    INSERT INTO reservationbody(reservationid,driverid,tripnumber,
                                           fromlocation,tolocation)
    SELECT 1, 2, MAX(tripnumber) + 1, 'here', 'there'
    FROM reservationbody
    WHERE reservationid = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to select distinct value from a multiple union. I nee to use
I need to get the biggest value from two fields: SELECT MAX(field1), MAX(field2) Now,
I need ruby to either take the value from an f.select or an f.text_field
I need to use the selected value of a select list when the form
I need to update a row in a table, and get a column value
SELECT COUNT(VALUE) FROM TABLE WHERE ID ='ID' AND BETWEEN 'DATE1' AND 'DATE2' It will
i have two dropdownchoice,After selecting value from first dropdownchoice i need to select list
I need to select some values from a json response. Im using json.net, fine
I need to select node which has a specific value: <td class='formlabel'>Name:</td> So I
I need to select records where a column value is LIKE any of the

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.