将列从一个表复制到具有多个行的另一个mysql

时间:2022-01-12 04:39:31

I have write this query

我已经写了这个查询。

INSERT INTO  table1 set Name=(SELECT Name FROM  table2)

it gives #1242 - Subquery returns more than 1 row error,

它给出#1242 -子查询返回多于一行错误,

please help me with the correct query.

请帮助我正确的查询。

thanks, krishna

谢谢,克利须那神

2 个解决方案

#1


4  

Your syntax for INSERT INTO ... SELECT is wrong. Try

插入的语法。选择是错误的。试一试

INSERT INTO table1 (Name)
SELECT Name FROM table2

Here is SQLFiddle demo.

这是SQLFiddle演示。

#2


3  

I think you should be doing INSERT INTO...SELECT statement,

我认为你应该做插入…SELECT语句,

INSERT INTO table1 (Name)
SELECT DISTINCT Name
FROM table2

#1


4  

Your syntax for INSERT INTO ... SELECT is wrong. Try

插入的语法。选择是错误的。试一试

INSERT INTO table1 (Name)
SELECT Name FROM table2

Here is SQLFiddle demo.

这是SQLFiddle演示。

#2


3  

I think you should be doing INSERT INTO...SELECT statement,

我认为你应该做插入…SELECT语句,

INSERT INTO table1 (Name)
SELECT DISTINCT Name
FROM table2