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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:51:38+00:00 2026-05-16T23:51:38+00:00

I have two tables: data and comments data: ——————- id | name | email

  • 0

I have two tables: data and comments

data:
-------------------
id | name | email |

pics:
-------------------
msg_id | pic |

The data is assosiated by id and msg_id. How I can merge this two tables into final one?

Edit: some rows in data don’t have associated a pic, and i need to keep them.

  • 1 1 Answer
  • 1 View
  • 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-16T23:51:38+00:00Added an answer on May 16, 2026 at 11:51 pm

    You may want to use the INSERT INTO ... SELECT syntax:

    INSERT INTO final_table
    SELECT id, name, email, pic
    FROM   data
    JOIN   pics ON (pics.msg_id = data.id);
    

    Example:

    Your current data:

    CREATE TABLE data (id int, name varchar(20), email varchar(100));
    INSERT INTO data VALUES (1, 'name1', 'a@example.com');
    INSERT INTO data VALUES (2, 'name2', 'b@example.com');
    INSERT INTO data VALUES (3, 'name3', 'c@example.com');
    INSERT INTO data VALUES (4, 'name4', 'd@example.com');
    
    CREATE TABLE pics (msg_id int, pic varchar(100));
    INSERT INTO pics VALUES (1, 'pic1.jpg');
    INSERT INTO pics VALUES (1, 'pic2.jpg');
    INSERT INTO pics VALUES (2, 'pic3.jpg');
    INSERT INTO pics VALUES (2, 'pic4.jpg');
    INSERT INTO pics VALUES (3, 'pic5.jpg');
    

    Your new table:

    CREATE TABLE final_table (
      id int, name varchar(20), email varchar(100), pic varchar(100)
    );
    
    INSERT INTO final_table
    SELECT      id, name, email, pic
    FROM        data
    LEFT JOIN   pics ON (pics.msg_id = data.id);
    

    Result:

    SELECT * FROM final_table;
    +------+-------+---------------+----------+
    | id   | name  | email         | pic      |
    +------+-------+---------------+----------+
    |    1 | name1 | a@example.com | pic1.jpg |
    |    1 | name1 | a@example.com | pic2.jpg |
    |    2 | name2 | b@example.com | pic3.jpg |
    |    2 | name2 | b@example.com | pic4.jpg |
    |    3 | name3 | c@example.com | pic5.jpg |
    |    4 | name4 | d@example.com | NULL     |
    +------+-------+---------------+----------+
    6 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two data tables with the same structure the first one has one
I have two Tables: Table 1: Questions : QuestionId NUMERIC Title TEXT Test Data
1I have the following two tables (sample data) and need to be able to
I have two tables set up in phpmyadmin- table userid and table data. The
I have a database with two tables: data and file . file_id is a
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have two different tables from which I need to pull data blogs which
I have two tables. One of them called conversations has the following data. ConversationID
I have two data tables. One contains all of users identifiable informaiton (username, id,
I have got two kind of entities, comments and tasks. Both types can be

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.