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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:02:32+00:00 2026-05-21T18:02:32+00:00

MYSQL Database: I have a table of data that I need to put into

  • 0

MYSQL Database:

I have a table of data that I need to put into two tables.The one table contains persons and an animal. Every record is a person and an animal. I am chaning this to a multi table database and want to group by the persons name, and then give the group an id (like a customer id) and then in my other table pass the customer ID to the idcustomer to join the two tables. To simplfy this i dont mind if these newly created ids are in the single table with new column names. I can after the fact export them out and import them.

The question really is, how can I create a group by customer name, give that customer and ID and then use that same id in a column to do the join.

To describe the scheme:

I have taken over a project. The database as of now is one table. In this one table is:

persons name, address, childsname, description of child

What would like it to be at least to start with is:

id_person, person name, childsname, childparent, description of child.

The id of the person and the childsparent should be the same. When I break the table down, and put the child information in the child table, the child will have a parent id.

I still plan on having two tables. But I can export and create the tables, my problem is assiging the parent id to the child column with the current data.

An example of a couple rows would be:

person_name, address, childsname, description

mark twain, 23 st., Buckweat, short smart kid

mark twain, 23 st., Daniel, short kinda smart

Instead i would like to have 2 tables, one for the parents and the other table is their children.

The way this database was setup, if one person has more than one child, there is another row that lists all of the same information.

What I have planned is to have multiple tables with a join.

The original database has no index, or unique identifier.

What I want to do is loop through the records, since there is no unique id, if the customer name is identical, meaning they are listed twice, then they must have more than one child.

In that case, i want to be able to go through the database and assign a id for the parents. and also ad another colum called parentid, which will be the child table.

  • 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-21T18:02:32+00:00Added an answer on May 21, 2026 at 6:02 pm

    To create the table you need you can use a temporary table – to which you will insert all parent names and give them IDs. Then you can update the existing table:

    CREATE TABLE name_to_id (
    `id` INT(11) AUTO_INCREMENT,
    `name` VARCHAR(256),
    PRIMARY KEY (`id`));
    
    INSERT INTO name_to_id (name)
    SELECT DISTINCT name FROM my_table;
    
    ALTER TABLE my_table
    ADD COLUMN id INT(11) FIRST,
    ADD COLUMN parent_id INT(11) AFTER childsname;
    
    UPDATE my_table t
    JOIN name_to_id n ON t.name = n.name
    SET t.id = n.id, t.parent_id = n.id;
    

    To create the parents and children separate tables you can use:

    CREATE TABLE parents AS
    SELECT id, name, address FROM my_table
    GROUP BY id;
    
    CREATE TABLE children AS
    SELECT childsname, parent_id, description
    FROM my_table;
    

    You would probably want to ALTER those tables later to add a primary keys and other needed indexes.

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

Sidebar

Related Questions

I have a user table in my mysql database that has a password column.
I have a MySql database with three tables I need to combine in a
I have a MySQL database table with a couple thousand rows. The table is
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a mysql database which has grown to over 200 tables in it.
We have a live MySQL database that is 99% INSERTs, around 100 per second.
I have a MySQL database of keywords that are presently mixed-case. However, I want
I have a MySQL database that I want to archive . What is the
I am working in PHP/MySQL. I have a table in my database called hourly
I have a table in a central database that gets constantly appended to. I

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.