从另一个表mysql插入数据

时间:2013-10-21 00:01:47

标签: mysql database

我想将值从表添加到另一个,但在第一个表中我有外键 如何插入它的值?

insert into student(first_name)
select * from `TABLE 13`
set school_id = 1

school_id是如何将其值设置为1

的forign键

2 个答案:

答案 0 :(得分:0)

你的意思是这样的:

insert into student(first_name)
VALUES( select first_name from `TABLE 13` WHERE school_id = 1 LIMIT 1 )

答案 1 :(得分:0)

尝试这样的事情:

INSERT INTO student(first_name,school_id)
SELECT first_name, 1 FROM `TABLE 13`

sqlfiddle demo