And in this case: a = SELECT ID FROM CN WHERE KOD=123456'; UPDATE CN SET KOD='000000' WHERE ID = a; At the same time the value is collected and update in the same table in the same query. UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD=123456'); This query throws an error;
And in this case: a = SELECT ID FROM CN WHERE KOD=123456'; UPDATE CN SET KOD='000000' WHERE ID = a; At the same time the value is collected and update in the same table in the same query. UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD=123456'); This query throws an error;
What error it is giving?
It seems you have missed single qoute
UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD='123456');
And in this case: a = SELECT ID FROM CN WHERE KOD=123456'; UPDATE CN SET KOD='000000' WHERE ID = a; At the same time the value is collected and update in the same table in the same query. UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD=123456'); This query throws an error;
What error it is giving?
Error: You can't specify target table 'CN' for update in FROM clause'.
And in this case: a = SELECT ID FROM CN WHERE KOD=123456'; UPDATE CN SET KOD='000000' WHERE ID = a; At the same time the value is collected and update in the same table in the same query. UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD=123456'); This query throws an error;
What error it is giving?
Error: You can't specify target table 'CN' for update in FROM clause'.
I tried here with sample data and this working
create table cn (id int,kod varchar(20))
insert into cn(id,kod)
select 1,'123456'
union all
select 1,null
union all
select 1,null
UPDATE CN SET KOD='000000' WHERE ID=(SELECT ID FROM CN WHERE KOD='123456')
SELECT * FROM CN
If possible can you provide sample data of your table
so that we can try to produce same error here.
Are you using SQL server or MYSQL ?
I guess you are using MYSQL then go through
http://www.xaprb.com/blog/2006/06/23/how-to-select-from-an-update-target-in-mysql/