Link to home
Start Free TrialLog in
Avatar of MISKid08
MISKid08

asked on

How to insert data into SQL table where a column name equals a different column namefrom another table.

I am a fairly new beginner with SQL and I having a couple of issues.

I want to insert data in a pre-existing table from a separate table. For instance, table A has a column entitled prod_id and table B has a column titled sold_prod_id. These values are the same, they are just named differently within the two tables (ITable B was prodived and I created table A based on a provided ERD). I have created a column within table A entitled sold_date. Table B contains the sold_date information, but I need it within table A. I have tried a WHERE clause and an INNER JOIN.

WHERE clause:

insert into a (sold_date)
select sold_date
from b
where a.prod_id = b.sold_prod_id

This is where I enounter the "The multi-part identifier 'a.prod_id' could not be bound."

INNER JOIN:

insert into a (sold_date)
select sold_date
from b
inner join a on b.sold_prod_id = a.prod_id

The inner join query inputs sold_date, but after all of the data within table a. It doesn't put the sold_date on the same row associated with the prod_id. I hope this isn't too confusing and any help is greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MISKid08
MISKid08

ASKER

You're amazing. Thanks for helping a beginner.