Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL:使用另一个表中的某些特定值在一个表中插入新记录_Mysql - Fatal编程技术网

MySQL:使用另一个表中的某些特定值在一个表中插入新记录

MySQL:使用另一个表中的某些特定值在一个表中插入新记录,mysql,Mysql,我有两个具有以下字段的表: 表名:字符 Columns: AccountID, CharacterID, CharName, ID1, ID2, ID3, Level 表名:bankitem Columns: CharID, Name, ItemID, Count, Type, ID1, ID2, ID3, Color, Effect1, Effect2, Effect3, LifeSpan, Attribute 我想在表bankitem中插入新行。我需要从一个表(字符)中查找信息,并使用其

我有两个具有以下字段的表:

表名:字符

Columns: AccountID, CharacterID, CharName, ID1, ID2, ID3, Level
表名:bankitem

Columns: CharID, Name, ItemID, Count, Type, ID1, ID2, ID3, Color, Effect1, Effect2, Effect3, LifeSpan, Attribute
我想在表bankitem中插入新行。我需要从一个表(字符)中查找信息,并使用其中的一些作为第二个表(bankitem)中的值。我只想定义CharID和ID1、ID2、ID3一次,尽管每行都有这些值

例如,字符表中的记录:

1000, 1500, WarriorBob, 1200, 905, -2345, 180
查询/插入:

SELECT * 
FROM  `character` 
WHERE  `CharName` LIKE  'WarriorBob'
LIMIT 0 , 1000
?


您可以使用
insert。选择

INSERT INTO bankitem (CharID, Name, ItemID, Count, Type, ID1, ID3, Color, Effect1, Effect2, Effect3, LifeSpan, Attribute)
    select CharacterID, 'ZemstoneofSacrifice', '650', '1', '2', ID1, ID2, ID3, '0', '0', '0', '0', '3', '0'
    from character c
    where charname = 'WarriorBob';

您看过
插入到tablename SELECT…
的文档了吗?Thank@joe love的可能副本-我如何集成同时添加多行的功能?
INSERT INTO bankitem (CharID, Name, ItemID, Count, Type, ID1, ID3, Color, Effect1, Effect2, Effect3, LifeSpan, Attribute)
    select CharacterID, 'ZemstoneofSacrifice', '650', '1', '2', ID1, ID2, ID3, '0', '0', '0', '0', '3', '0'
    from character c
    where charname = 'WarriorBob';
INSERT INTO bankitem 
(CharID, Name, ItemID, Count, Type, ID1, ID3, Color, Effect1, Effect2, Effect3, LifeSpan, Attribute)
(select CharacterID, ZemstoneofSacrifice', '650', '1', '2', ID1, ID2, ID3, '0', '0', '0', '0', '3', '0' 
from character where charname = 'WarriorBob')