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 7685921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:21:38+00:00 2026-05-31T19:21:38+00:00

When inserting a row into a table with an auto increment primary key column,

  • 0

When inserting a row into a table with an auto increment primary key column, is there a way to get the value that is going to be assigned to that row?

To be clear, I want to use this value as a part of a string for a different column on the same row.

Doing MAX(id) + 1 doesn’t seem robust enough.
And doing the insert and then an update with LAST_INSERT_ID() is bad because that’s 2 separate db calls.

Thanks

EDIT:

What does everyone think of this:

INSERT INTO `mydatabase`.`mytable` (`name`, `description`) 
VALUES
  (
    CONCAT(
      'name-',
      CAST(
        (SELECT 
          `auto_increment` + 1 
        FROM
          `information_schema`.`TABLES` 
        WHERE `TABLE_SCHEMA` = 'mydatabase' 
          AND `TABLE_NAME` = 'mytable') AS CHAR
      )
    ),
    'description of this thing'
  ) ;

This way, you should end up with a row with id of 5 for example, and a name of “name-5”. This is kind of a messy way to go about it, but it should work, no?

Thoughts?

  • 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-31T19:21:39+00:00Added an answer on May 31, 2026 at 7:21 pm

    You should look in to the SQL command “SHOW TABLE STATUS”

    Try it, and google further to find out how to pull the “auto_increment” value out of it.

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

Sidebar

Related Questions

I am inserting a row into a table and would like to get the
I want to make sure I'm not inserting a duplicate row into my table
First i gave all values of row in JTAble. While inserting table values into
I'm inserting multiple records into a table A from another table B. Is there
Using C# in Visual Studio, I'm inserting a row into a table like this:
Supposing I am inserting a row into a table in MySql by php code,
I'm inserting a row into a table, like so: mysql_query(INSERT INTO post(name,message,date)VALUES('$name','$message','$date')); The table
I'm successfully inserting a row into my table via $('#fbs tr:last').after('<tr><td><input id=vm type=checkbox /></td></tr>');
I am dynamically inserting a row into a table with JQuery using clone. $('#Clone').click(function()
In JTable, if you are inserting values to that row of 4 in first

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.