一种从一个表中选择字段并插入到另一个表的方法?
我有两个表,TableA 和 TableB
TableA 有 9 个字段 TableB 有 7 个字段
两个表中有 2 个相同的字段(id 和 name),有没有办法从 TableA 中仅选择这两个字段并将它们插入到 TableB 中?
我已经使用此语句查看了 INSERT INTO...SELECT 方法:
INSERT INTO TableB
SELECT id, name
FROM TableA
WHERE id = 1
但出现以下错误:
#1136 - Column count doesn't match value count at row 1
我认为此错误不允许我仅在表中插入 2 个字段?如果是这样,有没有办法解决这个问题或替代方法?
谢谢
I have two tables, TableA and TableB
TableA has 9 fields
TableB has 7 fields
There are 2 fields (id and name) that are identical in both tables, is there a way to select ONLY these two fields from TableA and insert them into TableB?
I have looked at the INSERT INTO... SELECT method using this statement:
INSERT INTO TableB
SELECT id, name
FROM TableA
WHERE id = 1
But I get the following error:
#1136 - Column count doesn't match value count at row 1
I assume this error is not allowing me to insert only 2 fields into the table? If so, is there a way around this or an alternative method?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
必须假设 TableB 中的列名称与 TableA 匹配,否则您需要输入正确的名称。
Try:
One would have to assume that the column names in TableB match TableA otherwise you would need to put in the right names.
您需要指定 TableB 的列名称(并且可能在 WHERE 子句中指定 TableA.id):
You need to specify the column names for TableB (and possibly specify TableA.id in the WHERE clause):
指定表b中的列
Specify the columns in table b