从一个表复制列并插入另一个表

时间:2012-05-14 10:41:55

标签: mysql

我有2个表:publicationsbooks.

目前,表publications为空。

我需要选择“书籍”表中卷“26”的所有书籍并将其插入出版物表格中。我还应该使用'thesorus'

填充列publications.component

我尝试了下面的sql,但似乎不正确:

INSERT INTO publications (book_fk, component) VALUES (SELECT book_id FROM books WHERE volume = 26, "thesorus");

任何建议都表示赞赏

3 个答案:

答案 0 :(得分:3)

正确的语法是:

INSERT INTO publications (book_fk, component) SELECT book_id, 'thesorus' FROM books WHERE volume = 26

答案 1 :(得分:1)

INSERT INTO publications (book_fk, component) SELECT book_id, 'thesorus' FROM books WHERE volume = 26;

答案 2 :(得分:0)

Insert into (field1,field2) select field1, field2 from table1