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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:11:05+00:00 2026-05-24T09:11:05+00:00

How do I use the information from existing MySQL tables to populate a new

  • 0

How do I use the information from existing MySQL tables to populate a new table. I have three tables each of which have a key that I want to include in the new table like so:

TRANSACTIONS TABLE
tr_id INT NOT NULL AUTO_INCREMENT
other columns
.
.

PEOPLE TABLE
p_id INT NOT NULL AUTO_INCREMENT
tr_id INT
other columns
.
.

HOLIDAYS TABLE
h_id INT NOT NULL AUTO_INCREMENT
tr_id INT
other columns
.
.

TRACKING TABLE
track_id INT NOT NULL AUTO_INCREMENT
tr_id
p_id
h_id
other columns
.
.

I’m not even sure that I need the p_id and h_id columns in the new table, because I just need to be able to get all the rows from the tracking table for a single tr_id, but they may come in useful, so I might leave them in there. (I do need them to create the rows in the new table because one transaction can relate to multiple people going on multiple holiday destinations and each row in the tracking table ust relate to a single destination for a single person, so for 2 people each going to the same 2 holiday destinations, there will be 4 rows in the tracking table)

I have tried:

INSERT INTO tracking (tr_id, p_id, h_id) VALUES 
(SELECT t.tr_id, p.p_id, h.h_id
  FROM transactions t 
  JOIN people p 
  JOIN holidays h
  WHERE t.tr_id = p.tr_id 
    AND t.tr_id = h.tr_id);

but this is giving me an error.

Grateful for any advice on this. Many thanks.

  • 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-24T09:11:06+00:00Added an answer on May 24, 2026 at 9:11 am

    There is a syntax error. When you use Join, it is followed by the ON keyword which specifies which columns need to match. The following query will work:

    INSERT INTO tracking (tr_id, p_id, h_id) VALUES 
    (SELECT t.tr_id, p.p_id, h.h_id
    FROM transactions t 
    JOIN people p 
    on t.tr_id = p.tr_id
    JOIN holidays h
    on t.tr_id = h.tr_id)
    

    You can read more about JOINS over here

    UPDATE

    This should work:

    INSERT INTO tracking (tr_id, p_id, h_id) 
    SELECT t.tr_id, p.p_id, h.h_id
    FROM transactions t 
    JOIN people p 
    on t.tr_id = p.tr_id
    JOIN holidays h
    on t.tr_id = h.tr_id
    

    Reference: MySQL Insert & Joins

    The reference that I have provided does not use the VALUES keyword in the query. Strange syntax, but let me know if that works.

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

Sidebar

Related Questions

I have an existing recordset that retrieves all the information from a table in
I have a web application that you can use to import information from another
In SQL you can use SELECT * FROM INFORMATION_SCHEMA.TABLES etc to get information about
I have a query that is created in VBA and selects column information from
I'm new to MySQL and have a few questions that I haven't been able
I have an existing WSDL which returns information to remote devices using SOAP. However,
I want to use Perl to extract information from a Certificate Signing Request ,
I trying to use ImageInfo and Jython to get information from a image on
I've been trying to use jQuery to grab the information from $_POST and return
I was trying to use http://www.jongsma.org/gc/scripts/ofx-ba.py to grab my bank account information from wachovia.

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.