我有两张桌子,A和B.
我想根据它的主键从B中选择一行,将主键更改为其他值,然后将该行插入A中。
这样的事情:
INSERT INTO A SELECT id, title, date FROM B WHERE B.id="4" UPDATE B SET id="5";
有解决方案吗?
答案 0 :(得分:1)
INSERT INTO A(id, title, date)
SELECT 5 AS id, title, date FROM B WHERE B.id="4";
# ^--- here is the trick
答案 1 :(得分:0)
也许像
insert into a (select id as "new_id", title, date from b where b.id="4")