我有两个表:

`user1`
- full_name
- headline # this is empty

`user2`
- full_name
- headline # this has content


我想将headlineuser2表插入到user1表中。这是我到目前为止所拥有的:

insert into user1 set headline = (select headline from user2 where headline=headline)


但是,我收到一条错误消息,说选择返回多于一行。我将如何正确发出此插入语句?

最佳答案

尚不清楚您要做什么。特别是,每个表中有多个记录时会发生什么?如果要将标题从user2复制到与user1匹配的full_name中,则可以使用多表UPDATE语法联接表并更新user1

UPDATE user1 JOIN user2 USING (full_name) SET user1.headline = user2.headline

关于mysql - INSERT…在mysql中选择查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11599794/

10-13 04:37