测试了这个语句,但是不可用。delete from testtable where name = (select name from testtable where id = 1) and age = (select age from testtable where id = 1) Error Code: 1093. You can't specify target table 'testtable' for update in FROM clause
自己解决了: delete from testtable where name = (select a.name from (select * from testtable where id = 1) as a) and age = (select b.age from (select * from testtable where id = 1) as b)
下面方法也是可以的: create table testtable (id int, sname char(10), age int, ActionFlage char(20), Actions char(20));insert into testtable values( 1,'李三',12,'离开动作','关门'), (2,'李三',12,'进入动作','开门'), (3,'李四',15,'离开动作','到水'), (4,'李四',15,'进入动作','开门'), (5,'李三',15,'离开动作','喝水'), (6,'李三',15,'进入动作','到水');select * from testtable;select * from testtable where id=1;delete from testtable where sname+age in (select distinct sname+age from testtable where id=1);
delete from testtable where name = (select a.name from (select * from testtable where id = 1) as a) and age = (select b.age from (select * from testtable where id = 1) as b)
create table testtable
(id int,
sname char(10),
age int,
ActionFlage char(20),
Actions char(20));insert into testtable values(
1,'李三',12,'离开动作','关门'),
(2,'李三',12,'进入动作','开门'),
(3,'李四',15,'离开动作','到水'),
(4,'李四',15,'进入动作','开门'),
(5,'李三',15,'离开动作','喝水'),
(6,'李三',15,'进入动作','到水');select * from testtable;select * from testtable where id=1;delete from testtable where sname+age in
(select distinct sname+age from testtable where id=1);
不知道楼主用的说明编辑器啊,我测试了一下没有报错啊!
印象里MySql不能这样自参照的吧,你用的是否是MSSQL?