错误 1064 - MySQL 中 INSERT 语句的 SQL 语法

发布于 2024-11-15 00:14:00 字数 628 浏览 2 评论 0原文

我正在尝试这个查询,但没有成功。

错误:#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 2 行的 '= (SELECT id_university FROM University WHERE University = "xxx") 、 `singl' 附近使用的正确语法

INSERT INTO `database_charts`.`university_has_single_user` (
        `university_id_university` = (SELECT id_university FROM university WHERE university = "xxx") , 
        `single_user_users_id_user` = (SELECT users_id_user FROM single_user WHERE users_id_user = "1" ), 
        `course_id_course`= (SELECT id_course FROM course WHERE course = "yyy"),
        `year`= "2000" ) 

如何解决这个问题?

i am trying this query but didn't work.

ERROR: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= (SELECT id_university FROM university WHERE university = "xxx") , `singl' at line 2

INSERT INTO `database_charts`.`university_has_single_user` (
        `university_id_university` = (SELECT id_university FROM university WHERE university = "xxx") , 
        `single_user_users_id_user` = (SELECT users_id_user FROM single_user WHERE users_id_user = "1" ), 
        `course_id_course`= (SELECT id_course FROM course WHERE course = "yyy"),
        `year`= "2000" ) 

How can this be solved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

已下线请稍等 2024-11-22 00:14:00

除非 MySQL 支持非常奇怪的语法,否则这不是编写 INSERT 语句的方式。它采用这种形式:

INSERT INTO <TableName> (<Column1,Column2,..,ColumnN>) VALUES (<Value1,Value2,..,ValueN>)

所以你会

INSERT INTO database_charts.university_has_single_user (
  university_id_university, 
  single_user_users_id_user, 
  course_id_course,year) 
VALUES (
  (SELECT id_university FROM university WHERE university = 'xxx'),
  (SELECT users_id_user FROM single_user WHERE users_id_user = '1' ),
  (SELECT id_course FROM course WHERE course = 'yyy'),
  '2000'
)

警告:我不确定MySQL是否会真正处理每个列值的嵌套SELECT,但上面 INSERT语句通常是这样写的。

Unless MySQL supports a very strange syntax, that's not how you write an INSERT statement. It takes this form:

INSERT INTO <TableName> (<Column1,Column2,..,ColumnN>) VALUES (<Value1,Value2,..,ValueN>)

So you would have

INSERT INTO database_charts.university_has_single_user (
  university_id_university, 
  single_user_users_id_user, 
  course_id_course,year) 
VALUES (
  (SELECT id_university FROM university WHERE university = 'xxx'),
  (SELECT users_id_user FROM single_user WHERE users_id_user = '1' ),
  (SELECT id_course FROM course WHERE course = 'yyy'),
  '2000'
)

Caveat: I'm not sure whether MySQL will actually handle a nested SELECT for each column value, but the above is how INSERT statements are typically written.

木落 2024-11-22 00:14:00
INSERT INTO TABLE2 (TABLE2_FIELD)
  SELECT TABLE1_FIELD
  FROM TABLE1 
  WHERE TABLE1_SOMEFIELD IS 'SOMETHING'

更多信息请参见http://dev.mysql.com/doc/refman /5.6/en/insert-select.html

INSERT INTO TABLE2 (TABLE2_FIELD)
  SELECT TABLE1_FIELD
  FROM TABLE1 
  WHERE TABLE1_SOMEFIELD IS 'SOMETHING'

More here http://dev.mysql.com/doc/refman/5.6/en/insert-select.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文