Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Query Result to another mysql table

Tags:

sql

mysql

I am trying to import a large CSV file into a MySQL database. I have loaded the entire file into one flat table. i can select the data that needs to go into separate tables using select statements, my question is how do i copy the results of those select queries to different tables. i would prefer to do it completely in SQL and not have to worry about using a scripting language.

like image 466
gsueagle2008 Avatar asked Dec 17 '22 08:12

gsueagle2008


2 Answers

INSERT
INTO    new_table_1
SELECT  *
FROM    existing_table
WHERE   condition_for_table_1;

INSERT
INTO    new_table_2
SELECT  *
FROM    existing_table
WHERE   condition_for_table_2;
like image 75
Quassnoi Avatar answered Jan 06 '23 11:01

Quassnoi


INSERT INTO anothertable (list, of , column, names, to, give, values, for)
SELECT list, of, column, names, of, compatible, column, types
FROM bigimportedtable
WHERE possibly you want a predicate or maybe not;
like image 43
tpdi Avatar answered Jan 06 '23 12:01

tpdi