mysql 查询语法有问题吗?尝试从 INNER JOIN 中插入

发布于 2025-01-07 23:15:51 字数 338 浏览 0 评论 0原文

下面的代码给了我一个模糊且无用的错误:

INSERT INTO database VALUES * FROM dbtemp WHERE dbtemp.number NOT IN (SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price);

我已经成功地在这些数据库上运行了其他查询,所以我知道这只是这个语句的语法问题。但就我的一生而言,我看不出有什么问题。任何建议/意见将不胜感激。

谢谢!

The following code is giving me a vague and unhelpful error:

INSERT INTO database VALUES * FROM dbtemp WHERE dbtemp.number NOT IN (SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price);

I've successfully run other queries on these databases, so I know its just a problem with the syntax of this statement. But for the life of me I can't see what's wrong. Any suggestions/advice would be greatly appreciated.

Thanks!

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

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

发布评论

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

评论(1

我还不会笑 2025-01-14 23:15:51

这应该是一个 INSERT INTO SELECT 语句吗?您的 INSERT INTO database VALUES * 语法值得怀疑...

INSERT INTO database
  SELECT * FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );

在执行这样的 INSERT SELECT 操作时,建议使用显式列名称,而不是 SELECT *,以确保它们以正确的顺序返回:

INSERT INTO database
  SELECT
    col1,
    col2,
    col3
  FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );

Should this have been an INSERT INTO SELECT statement? Your syntax of INSERT INTO database VALUES * is suspect...

INSERT INTO database
  SELECT * FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );

When doing an INSERT SELECT like this, it is advisable to use explicit column names, rather than SELECT *, to be sure they are returned in the correct order:

INSERT INTO database
  SELECT
    col1,
    col2,
    col3
  FROM dbtemp 
  WHERE dbtemp.number NOT IN (
    SELECT dbtemp.number FROM dbtemp INNER JOIN database ON dbtemp.number = database.number AND dbtemp.price = database.price
  );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文