mysql - 根据同一个表中的值更新 Mysql 表

标签 mysql sql

我有一个名为 questions 的表,其中包含列(id、标题、消息、永久链接)。我想根据值 title 更新 permalink 列,并用下划线替换标题中的空格。

这是我的查询:

UPDATE questions AS q SET permalink = SUBSTRING_INDEX(REPLACE(LOWER(b.title),' ','_'), '_', 4) FROM questions AS b;

但是我收到以下错误:

#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 questions AS b' at line 1

最佳答案

您的查询在单行上运行。您不需要别名或额外的选择,只需:

UPDATE questions
SET permalink = SUBSTRING_INDEX(REPLACE(LOWER(title),' ','_'), '_', 4):

关于mysql - 根据同一个表中的值更新 Mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59965759/

相关文章:

php - 尝试在 php 中使用 select 中的变量进行内部连接,但似乎无法正常工作

mysql - 如何将columnName及其值动态添加到MYSQL表中

mysql - 运行这个按计数的增加和减少排序的 MySQL 查询的最快方法是什么?

mysql - 无法在 Google Compute 上使用带有 PDO 的 SSL 连接到 Google Cloud MySQL

PHP MYSQL : instant select + insert

mysql 收集 1 :n relation into one record

mysql - 执行此 MySQL 查询的更好方法?

java - 将许多对象绘制到 JPanel 上的替代方法

c# - 如何分析慢查询?

mysql - 在单个查询中选择内部联接和更新