Insert multiple data from subquery into another table in postgres sql

半腔热情 提交于 2019-12-25 00:43:21

问题


I have table alpha with two columns

id   school_name

I have another table beta which has around 600 rows of data with following columns

id  school_name    school_state school_city

now i want to select school_name from beta and insert it into alpha

something like

insert into alpha (school_name) values(select school_name from beta )

but for all data ,I know it can be done with procedures but pgsql doesn't support procedures unlike mysql ,so how to achieve it?


回答1:


The INSERT INTO ... SELECT syntax does not use a VALUES clause. Fix your syntax slightly, and your query should work:

INSERT INTO alpha (school_name)
SELECT school_name
FROM beta;


来源:https://stackoverflow.com/questions/50369147/insert-multiple-data-from-subquery-into-another-table-in-postgres-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!