简体   繁体   English

从一个表中复制列,然后插入另一个表中

[英]copy column from one table and insert in another

I have 2 tables: publications and books. 我有2张桌子: publicationsbooks.

Currently, the table publications is empty. 当前,表publications为空。

I need to select all the books in the 'books' table with volume "26" and insert it in the publications table. 我需要在“图书”表中选择“ 26”卷中的所有图书,并将其插入出版物表中。 I should also populate the column publications.component with 'thesorus' 我还应在列publications.component添加“ thesorus”

I tried the sql below but it does not seem correct: 我尝试了以下sql,但它似乎不正确:

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

Any suggestion is most appreciated 任何建议都非常感谢

正确的语法是:

INSERT INTO publications (book_fk, component) SELECT book_id, 'thesorus' FROM books WHERE volume = 26
INSERT INTO publications (book_fk, component) SELECT book_id, 'thesorus' FROM books WHERE volume = 26;
Insert into (field1,field2) select field1, field2 from table1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM