用于在字段中的现有值前添加前缀的 SQL 查询 [英] SQL query to prepend prefix to existing value in a field

查看:33
本文介绍了用于在字段中的现有值前添加前缀的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并搜索了这个问题的答案,我认为对于任何了解 SQL 的人(不是我)来说,这一定是儿戏.

I have searched and searched for an answer to this, and I think this must be child's play for anyone who KNOWS SQL (which is not me).

我想在我的数据库中的表的字段中插入一个前缀.

I want to insert a prefix to the values in a field of a table in my DB.

更具体地说,我有一个表 jos_content,其中有一个字段title"(其中包含我的 joomla 站点的内容项的标题).

More specifically, I have a table jos_content in which I have a field 'title' (which contains the titles of the content items of my joomla site).

title"字段中的所有值都是个人姓名.现在我想要做的就是添加一个前缀先生".到该字段的所有值.

All the values in this field 'title' are names of individuals. Now all I want to do is add a prefix 'Mr.' to all the values of this field.

我可以在 phpmyadmin 中通过单击编辑铅笔图标并简单地在所有值前添加 Mr. 来执行此操作,但我有大约 750 行和一个可以插入前缀Mr."的 SQL 命令在这个字段的所有值前面会有很大的帮助.

I can do this from phpmyadmin by clicking the edit pencil icon and simply adding Mr. in front of all the values but I have about 750 rows and an SQL command which can insert a prefix of 'Mr.' in front of all values of this field will be a great help.

我已经阅读了有关更新"命令的内容,但该命令会用您提供的内容替换该值.但我想让这些值保留并在它们之前添加一个前缀.

I have read about the 'UPDATE' commands but that REPLACES the value with what you provide. But I want to let the values remain and add a prefix before them.

请谁能帮我用 SQL 命令来实现这一点?

Please can anyone help me achieve this with a SQL command ?

非常感谢.

推荐答案

您没有其他条件,例如在所有行中更新此内容,然后您可以尝试

You have no other conditions like update this in all rows then you can try

UPDATE jos_content SET title = CONCAT('Mr. ', title) 

如果你想有条件地更新这意味着特定的行需要更新你可以使用

if you want to update conditionally that means particular row needs to update the you can use

 UPDATE jos_content SET title = CONCAT('Mr. ', title)  where fiedl_name ='condition'

eg: UPDATE jos_content SET title = CONCAT('Mr. ', title)  where id = '1'

这只会更新包含 id=1 的一行.

this will update only one row which contain id=1.

在此之前的任何方式都应保留备份

any way before doing this should keep a backup

这篇关于用于在字段中的现有值前添加前缀的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆