为什么我在尝试使用 mysql-query 更新属性时遇到此语法错误?

发布于 2024-11-07 17:34:52 字数 1074 浏览 4 评论 0原文

我正在尝试使用以下 mysql 查询更新“目标”表的“pwd”列,但遗憾的是它给出了错误。 mysql 查询:

UPDATE Goal 
   SET pwd = (SELECT MD5(CONCAT(ID, LEFT(phone,3), '$=')) 
                FROM Esubmission);

错误:

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“FROM Esubmission)”附近使用的正确语法

。我的表格如下所示;

Esubmission
ID        | pnone       | email            |
--------------------------------------------
20378     | 00000000000 | [email protected]|
20379     | 00000000000 | [email protected]|
20380     | 00000000000 | [email protected]|

Goal
usr   | pwd | time|
--------------------
20378 |     |12:09|
20379 |     |15:29|
20380 |     |15:47|

I am trying to update 'pwd' column of 'Goal' table using following mysql query but sad thing is it gives error. mysql query:

UPDATE Goal 
   SET pwd = (SELECT MD5(CONCAT(ID, LEFT(phone,3), '$=')) 
                FROM Esubmission);

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 'FROM Esubmission)' at line 1

My tables are like below;

Esubmission
ID        | pnone       | email            |
--------------------------------------------
20378     | 00000000000 | [email protected]|
20379     | 00000000000 | [email protected]|
20380     | 00000000000 | [email protected]|

Goal
usr   | pwd | time|
--------------------
20378 |     |12:09|
20379 |     |15:29|
20380 |     |15:47|

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

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

发布评论

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

评论(2

惯饮孤独 2024-11-14 17:34:52

嗯......我想你真的想为每个用户设置密码(我认为),在这种情况下你需要有一个更新连接,这样你就可以消除你的多个值正在选择..因为按照您的方式,您正在将 pwd 的目标表中的所有值更新为相同的值...按照下面的方式,您将每个用户的 pwd 更新为基于与 ID 连接的行。假设 esubmission 表中的每个 usr 都有一行,这应该可以工作:


UPDATE Goal    
SET pwd = MD5(CONCAT(ID, LEFT(e.phone,3), '$='))                 
FROM Goal g, Esubmission e
where e.ID = g.usr

Hmm.... I'm thinking that you really want to set the password for each user (I think), in which case you'll need to have a join for the update, and that way you can eliminate your multiple values you are selecting.. because the way you have it, you're updating all the values in the Goal table for pwd to the same value... the way below, you update each users pwd to be based on the row joined with the ID. Assuming you have one row for each usr in the esubmission table, this should work:


UPDATE Goal    
SET pwd = MD5(CONCAT(ID, LEFT(e.phone,3), '$='))                 
FROM Goal g, Esubmission e
where e.ID = g.usr

傾城如夢未必闌珊 2024-11-14 17:34:52

我在这里测试过并且工作得很好。 MySQL 5.1.37

I tested it here and worked fine. MySQL 5.1.37

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