问题
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