2013-10-21 447 views
0

我想從表中添加值到另一個表,但在第一個表中我有外鍵 如何插入它的值?從另一個表插入數據mysql

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

學校ID是forign關鍵是如何設置你的意思是這樣它的值設置爲1

回答

0

嘗試是這樣的:

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

sqlfiddle demo

0

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

而不是我要插入到school_id特定值「1」 – user2884425

相關問題