SQL 插入?将数据从一个插入到另一个 [英] SQL Insert? insert data from one to another

查看:64
本文介绍了SQL 插入?将数据从一个插入到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请理解 SQL 目前不是我的强项之一,我有点不确定为什么我不能让查询执行此操作,这似乎是可能的.

Firstly please understand that SQL is not one of my strong areas at the moment and i am a little unsure why i cannot get the query to-do this, it seems possible.

我们正在运行一个 mysql 服务器 v5.1

we are running a mysql server v5.1

我有一个 filenotes 表,我需要将一条记录插入到我们拥有的客户列表中.

i have a filenotes table that i need to insert a single record into for a list of clients we have.

所以我这样做了.

insert into filenote(clientid, notetype, datetime, notedetails)
    VALUES (clienttable.clientid, 'info','2011-09-29 09:00:00', 'example note')

select clienttable.clientid from clienttable 
    where clienttable.clientid in (1,2,3,4,5,6,7,8,9)

然而,我不断从 SQL 中收到与 select 语句相关的错误,但错误中没有说明问题是什么,它只是说明.

however i keep getting errors from SQL relating to the select statement, there is no indication in the error to what the problem is though, it just states.

"您在 select clienttable.clientid 附近的 SQL 语法中有错误from clienttable where clienttable.clientid in ("

"you have an error in your SQL syntax near select clienttable.clientid from clienttable where clienttable.clientid in ("

虽然我知道有问题,但我看不出问题是什么.请注意表格中的字段名称不匹配.

whilst i know there is a problem there i cannot see what that problem would be. please be aware that the field names do not match in the tables.

这是我遵循的例子.

INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998

推荐答案

你混淆了两种不同风格的 INSERT.

You're mixing up two different styles of INSERT.

要使用与示例相同的方法,您需要执行以下操作:

To use the same method as your example, you'd need to do:

INSERT INTO filenote(clientid, notetype, datetime, notedetails)
SELECT clientid, 'info','2011-09-29 09:00:00', 'example note'
FROM clienttable
WHERE clienttable.clientid in (1,2,3,4,5,6,7,8,9)

或使用BETWEEN:

INSERT INTO filenote(clientid, notetype, datetime, notedetails)
SELECT clientid, 'info','2011-09-29 09:00:00', 'example note'
FROM clienttable
WHERE clienttable.clientid BETWEEN 1 AND 9

这篇关于SQL 插入?将数据从一个插入到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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