SQL命令将选定的内容从选定的行复制到其他行?
知道如何将名称、内容从 language_id = 1 的行复制到 language_id = 2 的行吗? SQL命令应该是什么样的?
我想要实现:
Any idea how to copy: name, content from rows where language_id = 1 to rows where language_id = 2?
How should SQL command look like?
I want to achive:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://dev.mysql.com/doc/refman/5.0 /en/insert-select.html 是你需要做的
http://dev.mysql.com/doc/refman/5.0/en/insert-select.html is what you need to do
假设您想要将 ProductID 从 lang1 更新到 lang 2
当然,这将为表中的每一行执行此操作,因此如果您想限制它,请确保通过 ProductID 来限制它
assuming it is the productid that you want to update from lang1 to lang 2
ofcourse this will do it for every row in the table so if you want to restrict it then make sure to restrict it by the productids
您的意思是将所有
language_id=1
行复制到language_id=2
行吗?我对 MySQL 语法的了解很差,所以我不敢给你所有的代码,但至少你可能会发现以下方法有用:
创建一个结构如下的临时表:
也就是说,包含
product_id
以及需要复制的所有列。使用
language_id=1
数据填充临时表。大概是这样的:使用临时表中的相应数据更新原始表中
language_id=2
的行。它可能看起来像这样:将临时表中的行插入到原始表中,其中产品没有
language_id=2
。像这样的事情:如果您不想更改已经存在的
language_id=2
数据,则应省略步骤 #3,并且您可能还想修改步骤 #2,以便它仅针对缺少language_id=2
的产品选择了language_id=1
数据。Did you mean copying all
language_id=1
rows tolanguage_id=2
ones?My knowledge of MySQL syntax is very poor, so I dare not give you all the codez, but at least you may find the following approach useful:
Create a temp table with the structure like this:
That is, include
product_id
and all the columns you need to copy.Populate the temp table with the
language_id=1
data. Probably like this:Update those rows in the original table where
language_id=2
with the corresponding data in the temp table. It may look like this:Insert the rows from the temp table into the original table, where the products don't have
language_id=2
. Something like this:If you didn't mean to change the already existing
language_id=2
data, then step #3 should be omitted and you might further want to modify step #2 in such a way that it selectedlanguage_id=1
data only for the products lackinglanguage_id=2
.