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
Contributors
11
Replies
12
Views
4 Years
Discussion Span
Last Post by mehnihma
Featured 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 Read More

  • I don't know the fields and tables of your DB, but the point is that you can make an insert from a select. Did you get that? Check those lins: http://dev.mysql.com/doc/refman/5.1/en/insert-select.html http://stackoverflow.com/questions/5391344/mysql-insert-with-select http://stackoverflow.com/questions/5907206/mysql-insert-into-tbl-select-from-another-table-and-some-default-values Read More

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?

Edited by mehnihma

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

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.

Edited by AleMonteiro

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.