简体   繁体   English

SQL将行复制到同一表中的另一行

[英]SQL copy row to another row in same table

I need to copy all values from row1 to row2 where now all records contains "no tiltle" 我需要将所有值从行1复制到行2,其中所有记录现在都包含“ noliple”

I already tried: 我已经尝试过:

UPDATE `table` SET name=@tmp:=name,name=meta_title,meta_title=@tmp WHERE name='No Title';
UPDATE `bb_product_description` SET name = meta_title WHERE meta_title="No  Title"

but is just copy "No title to all" 但只是复制“所有人无标题”

Please help me 请帮我

You could use a standard INSERT ... SELECT for this like so: 您可以这样使用标准的INSERT ... SELECT:

INSERT INTO table SELECT * FROM table WHERE meta_title='No Title';

Or be more selective (no pun intended)... 或者更具选择性(无双关语)...

INSERT INTO table (name, col2, col3...) SELECT meta_title, col2, col3... FROM table WHERE meta_title = 'No Title'

Which, if I'm understanding your question correctly, should get you where you want to go. 如果我正确地理解了您的问题,那么应该可以将您带到您要去的地方。

Or, you could fix your UPDATE statement from above: 或者,您可以从上面修复UPDATE语句:

UPDATE `bb_product_description` SET `name` = `meta_title` WHERE `meta_title` = 'No Title'

Note I removed the extra space in 'No Title' and changed from double- to single-quote because safety. 请注意,出于安全考虑,我删除了“无标题”中的多余空间,并从双引号更改为单引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM