1.11M Members

MYSQL update query

 
0
 

I need to update values form one table to another and create values if they are not there
How can I do this for all values or form values from one ID to another

This is the query but I need to run it for every ID and that is a lot of job, so is there any simplier way?

So id_product is always the same

`

INSERT INTO ps_product_supplier 
(id_product_supplier, id_product, id_product_attribute, id_supplier, product_supplier_reference, product_supplier_price_te, id_currency)  
VALUES(NULL, 6216, 0, (SELECT id_supplier FROM ps_product WHERE id_product = 6216), (SELECT supplier_reference FROM ps_product WHERE id_product = 6216), 
(SELECT wholesale_price FROM ps_product WHERE id_product = 6216), 3);

`

 
2
 

Use a select from the ps_product table to insert into ps_product_supplier. Something like this:

INSERT INTO ps_product_supplier 
(id_product_supplier, id_product, id_product_attribute, id_supplier, product_supplier_reference, product_supplier_price_te, id_currency)  

SELECT
    NULL, id_product, 0, id_supplier, supplier_reference,  wholesale_price , 3
FROM 
    ps_product
 
0
 

Wihout any restrictions?
With this I will owerwrite id_product?

 
0
 

What this script does is:

Select the specified columns from ps_products, and insert each returned row into ps_product_suplier.

The table ps_product will not be changed.

 
0
 

But it does not inserts anything in table, any ideas?

 
0
 

Or can I write PHP to do this?

 
0
 

Does it throw any errors?
First test only the select part and see if it returns any rows.

Yes, you could do it with PHP. You'd have to make a select on the rows you want to insert, then loop thru them and insert each record.

 
0
 

It returns 0 rows changed?

 
0
 

This select return 0 rows?

SELECT
    NULL, id_product, 0, id_supplier, supplier_reference,  wholesale_price , 3
FROM 
    ps_product

If so, it means that there's no rows in your table.

 
0
 

That does not work
this is in ps_product_supplier:

id_product_supplier, id_product, id_product_attribute, id_supplier, product_supplier_reference, product_supplier_price_te, id_currency

NULL is there for id_product_supplier

 
2
 
 
0
 

Yes, I will try
Thanks

Question Answered as of 1 Year Ago by AleMonteiro
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article