MYSQL更新语句-未知列

发布于 2024-12-08 06:21:11 字数 552 浏览 0 评论 0原文

我有一个可以与以下输出正确配合的选择查询:

在此处输入图像描述

我想创建一个更新语句设置 despgoods_alldetails.loadid 列的值 = loaddetails.loadid,其中 despgoods_alldetails_despgoodsid=loaddetails.despgoodsid.loadid。

我在想

更新 despgoods_alldetails 设置 despgoods_alldetails.loadid = loaddetails.loadid 其中 despgoods_alldetails.despgoodsid=loaddetails.despgoodsid

此查询失败并出现以下错误: 在此处输入图像描述

知道如何让此更新语句发挥作用吗?

谢谢, 瑞安

I have a select query which works correctly with the below output:

enter image description here

I would like to create an update statement to set the value of the despgoods_alldetails.loadid column = loaddetails.loadid where despgoods_alldetails_despgoodsid=loaddetails.despgoodsid.loadid.

I was thinking along the lines of

update despgoods_alldetails
set despgoods_alldetails.loadid = loaddetails.loadid
where despgoods_alldetails.despgoodsid=loaddetails.despgoodsid

This query fails with the below error:
enter image description here

any idea how I can get this update statement to work?

Thanks,
Ryan

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

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

发布评论

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

评论(4

眸中客 2024-12-15 06:21:11

差不多了,你只需要参考第二个表。

UPDATE despgoods_alldetails, loaddetails
    SET despgoods_alldetails.loadid = loaddetails.loadid
    WHERE despgoods_alldetails.despgoodsid=loaddetails.despgoodsid

Almost had it, you just need a reference to the second table.

UPDATE despgoods_alldetails, loaddetails
    SET despgoods_alldetails.loadid = loaddetails.loadid
    WHERE despgoods_alldetails.despgoodsid=loaddetails.despgoodsid
笙痞 2024-12-15 06:21:11

loaddetails 是一个独立于您尝试更新的表的表。这不能直接在 SQL 更新中完成。您需要像这样的子选择:

update despgoods_alldetails
set despgoods_alldetails.loadid = (
    select loaddetails.loadid
    from loaddetails
    where despgoods_alldetails.despgoodsid=loaddetails.despgoodsid
)

loaddetails is a separate table from the one you are trying to update. This can't be done directly in a SQL update. You'll need a subselect like this instead:

update despgoods_alldetails
set despgoods_alldetails.loadid = (
    select loaddetails.loadid
    from loaddetails
    where despgoods_alldetails.despgoodsid=loaddetails.despgoodsid
)
回首观望 2024-12-15 06:21:11

您需要在更新子句后放置两个表,如下所示

update despgoods_alldetails, loaddetails set despgoods_alldetails.loadid =     loaddetails.loadid where despgoods_alldetails.despgoodsid=loaddetails.despgoodsid

您可以在本页中找到一个简单的示例 http://dev.mysql.com/doc/refman/5.0/en/update.html

UPDATE items,month SET items.price=month.price WHERE items.id=month.id;

You need to put two tables after update clause like this

update despgoods_alldetails, loaddetails set despgoods_alldetails.loadid =     loaddetails.loadid where despgoods_alldetails.despgoodsid=loaddetails.despgoodsid

Can you found one simple example in this page http://dev.mysql.com/doc/refman/5.0/en/update.html

UPDATE items,month SET items.price=month.price WHERE items.id=month.id;
素食主义者 2024-12-15 06:21:11
update  
  despgoods_alldetails as da
join 
  loaddetails as l
using 
  (despgoodsid)
set 
  da.loadid = l.loadid;
update  
  despgoods_alldetails as da
join 
  loaddetails as l
using 
  (despgoodsid)
set 
  da.loadid = l.loadid;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文