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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:54:58+00:00 2026-05-22T14:54:58+00:00

I have 2 tables like below structure. Both are identical except of table name.

  • 0

I have 2 tables like below structure. Both are identical except of table name.

tbl_item_color_exp
>>item_color_ID
>>color_ID
>>item_ID

tbl_item_color_live
>>item_color_ID
>>color_ID
>>item_ID

I wished to copy several rows from tbl_item_color_live table to tbl_item_color_exp table. I can accomplished copying the exact column and row by the following SQL below:

INSERT INTO tbl_item_color_exp 
SELECT * FROM tbl_item_color_live WHERE item_ID = $oldID

But I don’t want to create replicate item_color_ID primary key and I want to update all rows copied’s item_ID column to a new variable, $newID. The general idea is copy all rows based on $oldID and update destination table with &newID but maintaining color_ID column with a auto incremented primary key item_color_ID.

I can accomplish it using several SQL queries but I was wondering if it is possible for me to do everything in more efficient manner by just one SQL line? I hope my question can be understandable by all, thank you.

  • 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-22T14:54:58+00:00Added an answer on May 22, 2026 at 2:54 pm

    I’m not 100% sure I understand what you want, but it sounds like you only actually want to copy the color_ids, you want to set them all with a new item_id, and you want autonumbering to occur.

    Sounds like:

    INSERT INTO tbl_item_color_exp (color_id,item_id)
    SELECT color_id,$newID FROM tbl_item_color_live WHERE item_ID = $oldID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that I have a table structure like seen below location|name ------------- NY|john London|neil
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have a table structure like below : categoryID bigint , primary key ,
I have table structure like below: events (boxing, sparring etc) competitors (users who are
I have a table structure like the one shown below: <table id=result> <tr> <td
i have a t_my_class table structure like below (MySql table) id class group age
I have 3 tables with values like below **tbl_product** recID pID price colour 1
I have two tables like the ones below. I need to find what exchangeRate
I have a few tables that I've defined like the below examples: class TableA

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.