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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:14:19+00:00 2026-06-01T16:14:19+00:00

I am building upon an existing database with a relationship construction I’ve seen nowhere

  • 0

I am building upon an existing database with a relationship construction I’ve seen nowhere before.

I have three tables:

legend1
legid       INT(11), AUTO_INCREMENT, PRIMARY
description VARCHAR(255)

legend2
legid       INT(11), AUTO_INCREMENT, PRIMARY
description VARCHAR(255)

items
id          INT(11), AUTO_INCREMENT, PRIMARY
name        VARCHAR(255)
legid       INT(11)
legend      VARCHAR(8)

Every record in items relates to data in either legend1 or legend2.
The field items.legend determines wich one it is. I want to get rid of this construction as legend1 and legend2 have an identical structure. The only thing different is the content.

I want to have this construction:

legend
legid       INT(11), AUTO_INCREMENT, PRIMARY
description VARCHAR(255)

items
id          INT(11), AUTO_INCREMENT, PRIMARY
name        VARCHAR(255)
legid       INT(11)

The problem is that the tables are full and no data may be lost. The id of both tables starts on 1 so almost every primary key will collide.

I have this query:

INSERT INTO legend1 (description) SELECT description FROM legend2;

This query doesn’t work because it messes up referenced id’s from legend2.

  • 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-01T16:14:20+00:00Added an answer on June 1, 2026 at 4:14 pm

    After you have executed your insert query:

    INSERT INTO legend1 (description) SELECT description FROM legend2;

    Perform the following query

    UPDATE items SET legid = (SELECT legid FROM legend1 WHERE legend1.description = items.description) WHERE legend ='something to define that it is from the legend2 table'

    Note that I haven’t tried the query out but the solution is somewhat like this. If you pick out the syntax errors I’ve made I’m sure it will work.

    What it does is the following:
    After you insert your entire legend2 table into the legend1 table you update your items table to set the corresponding legendid

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

Sidebar

Related Questions

I'm looking at building a Rails application which will have some pretty large tables
I am building a web application that is dependent upon several third-party libraries. What
I'm building a Rails app which creates a bookmarklet file for each user upon
I am building an application that calls upon a compiled executable. Said executable's source
I'm currently building a live web application based upon the PubSubHubBub protocol. However, I
I am building an win32 application that is statically linked with OpenCV libraries. Upon
Upon building an MVC framework in PHP I ran into a problem which could
I'm building a web application that relies upon the Facebook API. I want to
building upon the $.fn.serializeObject() function from this question , i'd like to be able
Lets say I'm building a base class which will be extended upon by 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.