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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:09:18+00:00 2026-05-27T16:09:18+00:00

I have a mysql table that stores a mapping from an ID to a

  • 0

I have a mysql table that stores a mapping from an ID to a set of values:

CREATE TABLE `mapping` (
  `ID` bigint(20) unsigned NOT NULL,
  `Value` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

This table is a list of values and the ID of a row selects the set, this value belongs to.
So the column ID is unique per set, but not unique per row.

I insert data into the table using the following statement:

INSERT INTO `mapping`
SELECT 5, `value` FROM `set1`;

In this example I calculated and set the ID manually to 5.
It would be great if mysql could set this ID automatically. I know the autokey feature, but using it will not work, because all rows inserted with the same insert statement should have the same ID.

So each insert statement should generate a new ID and then use it for all inserted rows.
Is there a way to 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-05-27T16:09:19+00:00Added an answer on May 27, 2026 at 4:09 pm

    I am not convinced to it (I’m not sure whether locking table is good idea, I think it’s not), but this might help:

    lock tables `mapping` as m write, m as m1 read;
    
    insert into m
    select (select max(id) + 1 from m1), `value` from `set1`;
    
    ulock tables;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table in MySQL that stores values normally, but I want
I have a table that stores values each hour from a website based on
I have mysql table that has a column that stores xml as a string.
I have a MySQL table that defines values for a specific customer type. |
This is the MySQL table structure that I have: itemID (BIGINT) userID (BIGINT) wasAdded
I have columns in a mysql table that stores names of people as combinations
I have a table that stores a value that will be added to over
I have a table say, ITEM, in MySQL that stores data as follows: ID
So I have this function that takes all the users from an MySql table
I have a MySQL table pedigree that stores all my interconnecting parentage data as

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.