Member Avatar for mehnihma

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);

`

Recommended Answers

All 11 Replies

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
Member Avatar for mehnihma

Wihout any restrictions?
With this I will owerwrite id_product?

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.

Member Avatar for mehnihma

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

Member Avatar for mehnihma

Or can I write PHP to do this?

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.

Member Avatar for mehnihma

It returns 0 rows changed?

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.

Member Avatar for mehnihma

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

Member Avatar for mehnihma

Yes, I will try
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.