MySQL Forums
Forum List  »  New in 4.1: Subqueries

Re: Problem with Nested Inserts
Posted by: Juan Javaloyes
Date: July 27, 2005 01:21PM

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

Options: ReplyQuote


Subject
Views
Written By
Posted
6394
July 26, 2005 04:23PM
3516
July 26, 2005 06:59PM
3143
July 27, 2005 12:23PM
Re: Problem with Nested Inserts
3804
July 27, 2005 01:21PM
3411
July 27, 2005 02:11PM
3373
July 27, 2005 03:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.