Skip to content
Advertisement

postgresql: how to import data from two separate tables into a single table into the SAME row?

I am using postgresql to create countries table from single_sales_records. single_sales_records looks like this:

Before this, I created a regions table, which basically looks like this:

The countries table (1 region can have many countries) that I want to create is supposed to look like this:

I have a query that helped me to populate my ‘regions’ table:

And I am having trouble with my current query that is supposed populate by ‘countries’ table:

When I do this, my ‘countries’ table doesn’t match a country that is inside a region – instead it lists all the country, and then add 7 additional lines for the regions. it looks like this:

Can someone please help me to match the country with the associated region?

I tried to look for other so articles, but they were talking about inserting data INTO two separate tables, or talking about joins (i don’t think this would exactly require join… right?).

Thank you so much! [This article was edited to include single_sales_records]

Advertisement

Answer

You want to JOIN the tables together for the INSERT:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement