从一个列复制到另一个(不同的表同一个数据库)mysql [英] Copy from one column to another (different tables same database) mysql

查看:135
本文介绍了从一个列复制到另一个(不同的表同一个数据库)mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想将整个内容从表IName下的列项目复制到属于同一数据库的表项目下的列名称。



我给了以下查询,但它引发错误,说子查询返回了多个记录。 (共有大约600条记录)

 插入到项目集名称(从IName选择项目)

感谢

解决方案

  INSERT INTO Item(Name)
SELECT Item
FROM IName


$ b b




当您要插入到单列*表中时, INSERT 可以与:

  INSERT INTO表(列)
VALUES(value1),(value2),...(valueN);

或:

  INSERT INTO表(列)
SELECT a_column
FROM a_table
---可选(多个)JOINs
---和WHERE
- - 和GROUP BY
---任何复杂的SELECT查询

,上面可以使用多列表,只要所有其他 - 在INSERT语句中没有明确说明 - 列已经定义了一个 DEFAULT 值或 AUTO_INCREMENT 。)






INSERT ... SET 语法在MySQL中有效,只能在要插入一行时使用:

  INSERT INTO表
SET column = value1;

等效于:

  INSERT INTO表(列)
VALUES(value1);


Hi I would like to copy entire contents from column Item under table IName to column Name under table Item both belonging to the same database.

I am giving the following query but it throws the error saying that the subquery returned more than one records. (There are around 600 records)

Insert into Item set name = (Select Item from IName)

Thanks

解决方案

INSERT INTO Item (Name)
  SELECT Item 
  FROM IName


When you want to insert into a single-column* table, INSERT works either with:

INSERT INTO table (column)
  VALUES (value1),(value2), ... (valueN) ;

or with:

INSERT INTO table (column)
  SELECT a_column 
  FROM a_table
                       --- optional (multiple) JOINs
                       --- and WHERE
                       --- and GROUP BY      
                       --- any complex SELECT query

(OK, the above can work with a multiple-column table, too, as long as all the other - not explicitely stated in the INSERT statement - columns have been defined with a DEFAULT value or with AUTO_INCREMENT.)


The INSERT ... SET syntax is valid in MySQL only and can be used only when you want to insert one row exactly:

INSERT INTO table 
  SET column = value1 ;

is equivalent to:

INSERT INTO table (column)
  VALUES (value1) ;

这篇关于从一个列复制到另一个(不同的表同一个数据库)mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆