0
I am running this PROCEDURE, and it returns this error!
BEGIN
SET @cont = 0;
REPEAT
SET @sqlstring = "UPDATE import2016 SET coluna4 = (SELECT coluna4 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01) WHERE id = (SELECT id+7 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01);";
PREPARE stmt FROM @sqlstring ;
EXECUTE stmt USING @cont,@cont;
DEALLOCATE PREPARE stmt;
SET @cont = @cont +1;
UNTIL @cont = 256
END REPEAT;
END
/* Erro SQL (1093): You can't specify target table 'import2016' for update in FROM clause */
PROCEDURE is on the same bench! I’d like to know how I can fix this mistake, thank you.
tried to use the aliases you put in the Queries ?
UPDATE import2016 SET coluna4 = (SELECT a.coluna4 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01) WHERE id = (SELECT a.id+7 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01);
– Rovann Linhalis
I’m sorry but I didn’t mean what you meant, I thank you for your reply!
– Matheus Piano
in the subquerie, you put the table alias
import2016
asa
[import2016 AS a
], but the select column was justcoluna4
, without the alias. I only suggested that you also put the alias in the sub selects, because SGDB can understand that that column is the table that is informed in the update. (Even if it is the same table)– Rovann Linhalis
In this way?
"UPDATE import2016 AS a SET a.coluna4 = (SELECT a.coluna4 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01) WHERE id = (SELECT a.id+7 FROM import2016 AS a WHERE a.coluna2 ='' and a.coluna4 like'%/%' LIMIT ?,01);";
– Matheus Piano