复制行并在源表中插入

时间:2011-03-02 09:56:55

标签: mysql copy

在MySQL中,我有一个像这样的表格设计:

Language|Key|Text 

语言和密钥是主键。内容示例可能是:

("ENU","P_Home_H2","Welcome to my page"),
("ENU","P_Home_P1","Hello world!")

现在我想用Language =“ENU”将所有行复制到Language =“ESP”,即选择Language =“ENU”的所有行并插入到同一个表中,使用相同的键和文本但语言=“ESP” 。结果将是:

("ESP","P_Home_H2","Welcome to my page"),
("ESP","P_Home_P1","Hello world!")

我该怎么做?

2 个答案:

答案 0 :(得分:2)

Insert into MyTable
Select 'ESP' as Language, Key, Text
From MyTable 
Where Language = 'ENU'

答案 1 :(得分:0)

INSERT INTO existingTable
Select 'ESP' as Language, [Key], Text
FROM newTable
WHERE Language = 'ENU'