下表是模拟来说明我遇到问题的情况:
master: code | ord
sub: code | status
我想使用连接上的 'in' 表达式更新 'sub' 行子集中的字段,如下所示:
create table master (code text, ord integer);
insert into master (code, ord) values
('111', 4),
('222', 3),
('333', 1),
('444', 2),
('555', 0),
('666', 5);
create table sub (code text, status char default 'a');
insert into sub (code) values
('111'),
('222'),
('333'),
('444'),
('555'),
('666');
update sub set status='b' where code in (select sub.code from sub inner join master
on sub.code=master.code where sub.status='a' order by master.ord limit 3);
所以上面看起来工作正常,但我真正想要的是对两列连接的表应用相同的操作,如:
create table master (code1 text, code2 text, ord integer);
insert into master (code1, code2, ord) values
('111', 'one', 4),
('222', 'two', 3),
('333', 'three', 1),
('444', 'four', 2),
('555', 'five', 0),
('666', 'six', 5);
create table sub (code1 text, code2 text, status char default 'a');
insert into sub (code1, code2) values
('111', 'one'),
('222', 'two'),
('333', 'three'),
('444', 'four'),
('555', 'five'),
('666', 'six');
update sub set status='b' where code1, code2 in (select
sub.code1, sub.code2 from sub inner join master on sub.code1=master.code1 and
sub.code2=master.code2 where sub.status='a' order by master.ord limit 3);
>>>
Error: near ",": syntax error
如何执行此操作?