Link to home
Start Free TrialLog in
Avatar of AntonioRodrigo
AntonioRodrigo

asked on

Update each row in the table based on results

Hello,

I have a DataTable of my customers orders with one empty column. My columns:

ID
ID_Name

ID_Name is the empty column. I am getting values for this column from another table, called products, which has ID's and names of each product:

ID_PROD
ID_Name_prod


ID_PROD is a foreign key for customers table (ID column).

How to update ID_Name column from customers table? I wanna get ID_Name_prod for each row in the customers table and update that row, which is initially empty.

And idea?

I am selecting ID_Name_prod with the query:

Select Producst.ID_Name_prod
FROM customers LEFT JOIN products
ON customers.ID = products.ID_Name_prod

This query returns column with all the products names - but how to update each row in my customers table?


Greetings, Frenky
ASKER CERTIFIED SOLUTION
Avatar of sachinpatil10d
sachinpatil10d
Flag of India 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
ID_PROD replaced with ID_Name_prod


update Products set ID_Name = ID_Name_prod
FROM customers LEFT JOIN products
ON customers.ID = products.ID_PROD

Open in new window

SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America 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
SOLUTION
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

Hi,
your question is bit unclear for me.
you saying you will getting products name from ID_Name_prod,
but you put same in
customers.ID = products.ID_Name_prod

there are many products for one customer.....


- Bhavesh
SOLUTION
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