Thursday, September 24, 2009

MYSQL: Bulk Insert

In mysql, we can quickly insert many rows into a table from one or many tables. This we can easily achive using the insert_select.
insert_select statment syntax
INSERT [LOW_PRIORITY HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] SELECT ... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
Example:
INSERT INTO table1 (name, description) SELECT c.name,c.description FROM table2 c

No comments: