Re: Problem with Nested Inserts
Juan Javaloyes wrote:
> I'm going to give the exact case. Got two tables.
> prod_suc: @id_suc, @id_prod, cod_prod, cantidad,
> stockini, precio1, precio2
> prod_cant: @codigo, stock, preciom, preciom2
>
> All rows on prod_suc are full, except cantidad,
> stockini, precio1, precio2. These are the columns
> I want to fill with data from prod_cant, where
> prod_suc.cod_prod = prod_cant.codigo.
>
> INSERT INTO prod_suc (cantidad, stockini,
> precio_may1, precio_may2)
> SELECT stock, stock, preciom, preciom2
> FROM prod_cant
> INNER JOIN prod_suc
> ON prod_cant.codigo = prod_suc.cod_prod
>
> Result: #1216 - Cannot add or update a child row:
> a foreign key constraint fails
Maybe I should use update instead. Anyway, I need to use Update with a similar problem and don't know how, replacing some values with others from another table