MySql 1093 Error: You can't specify target table 'c1' for update in FROM clause
-
I am trying to execute the following update query:
update committees c1 set num_subcommittees =
case
when parent_committee is not null then -1
else (select count(*) from committees c2 where c2.parent_committee = c1.id)
end;But instead getting mySql 1093 error. The table structure is like this:
CREATE TABLE `committees` (
`id` char(5) NOT NULL,
`parent_committee` char(5) DEFAULT NULL,
`name` char(200) DEFAULT NULL,
`chairman` char(40) DEFAULT NULL,
`ranking_member` char(40) DEFAULT NULL,
`num_subcommittees` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;Please comment.
-
I am trying to execute the following update query:
update committees c1 set num_subcommittees =
case
when parent_committee is not null then -1
else (select count(*) from committees c2 where c2.parent_committee = c1.id)
end;But instead getting mySql 1093 error. The table structure is like this:
CREATE TABLE `committees` (
`id` char(5) NOT NULL,
`parent_committee` char(5) DEFAULT NULL,
`name` char(200) DEFAULT NULL,
`chairman` char(40) DEFAULT NULL,
`ranking_member` char(40) DEFAULT NULL,
`num_subcommittees` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;Please comment.
What is c1? Just use
committees
to update the table. PHP Update Data in MySQL[^]The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~