[英]Copy/ Update the primary keys value to another column of the same table
I have a MySQL database table subscribers as shown below: 我有一个MySQL数据库表订户 ,如下所示:
all i need is make the subscriber_number same as subscriber_id. 我需要做的就是使subscriber_number与users_id相同。
Eg: If subscriber_id is 261 and subscriber_number is 262 , then i need to make subscriber_number as 261, same as the subscriber id. 例如:如果subscriber_id为261,subscriber_number为262,那么我需要将subscriber_number设为261,与用户id相同。
Could you please help me with MySQL query to sort this out ? 您能否通过MySQL查询帮助我解决此问题?
UPDATE 1: 更新1:
am looking to get MySQL query from you experts here. 希望从这里的专家那里获得MySQL查询。 what i tried was to get the rows where both id and number are different
我尝试的是获取ID和编号都不同的行
SELECT subscriber_id,subscriber_number
FROM subscribers
WHERE subscriber_id <> subscriber_number
Please run the code snippet below to view the table structure with sample data 请运行下面的代码片段以查看带有示例数据的表结构
<table> <thead> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">subscriber_id</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">subscriber_number</td> </tr> </thead> <tbody> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">260</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">260</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">261</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">262</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">262</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">264</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">263</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">272</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">264</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">274</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">266</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">277</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">268</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">282</td> </tr> <tr> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">269</td> <td style="border-right:1px solid #000;border-bottom:1px solid #000;">269</td> </tr> </tbody> </table>
The SQL would be SQL将是
UPDATE subscribers SET subscriber_number = subscriber_id
This will set the subscriber_number to subscriber_id for every single row in your subscriber-table. 这会将订户表中每一行的subscriber_number设置为subscriber_id。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.