我有两张桌子:
`user1`
- full_name
- headline # this is empty
`user2`
- full_name
- headline # this has content
我想将headline
从user2
表插入到user1
表中。这就是我到目前为止所做的:
insert into user1 set headline = (select headline from user2 where headline=headline)
但是,我收到一条错误消息,说select会返回多行。我如何正确发出此插入语句?
答案 0 :(得分:1)
目前还不完全清楚你想做什么。特别是,当每个表中有多个记录时会发生什么?如果您要将标题从user2
复制到user1
匹配的full_name
,则可以使用多表UPDATE
语法来连接表并更新{{1 }}:
user1
答案 1 :(得分:0)
如果你真的想要INSERT那么你想要
INSERT INTO user1 SELECT full_name, headline
如果你真的想要更新,那么你想要
UPDATE user1 SET headline = (SELECT headline FROM user2 WHERE user1.full_name = user2.full_name)