Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
テーブルから別のテーブルに値を追加したいのですが、最初のテーブルには外部キーがあり、その値を挿入する方法は?
insert into student(first_name) select * from `TABLE 13` set school_id = 1
school_id は、その値を 1 に設定する方法の外部キーです
次のような意味ですか。
insert into student(first_name) VALUES( select first_name from `TABLE 13` WHERE school_id = 1 LIMIT 1 )
次のようなことを試してください:
INSERT INTO student(first_name,school_id) SELECT first_name, 1 FROM `TABLE 13`
sqlfiddle demo