Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mySQL :: insert into table, data from another table?

Tags:

sql

mysql

I was wondering if there is a way to do this purely in sql:

q1 = SELECT campaign_id, from_number, received_msg, date_received 
     FROM `received_txts` WHERE `campaign_id` = '8';
INSERT INTO action_2_members (campaign_id, mobile, vote, vote_date)    
    VALUES(q1.campaign_id, q1.from_number, q1.received_msg, q1.date_received);

Note: q1 would return about 30k rows.

Is there any way to do what I am attempting above in straight sql? To just pull the data straight from one table (basically a raw data table) and insert into another table (basically a processed data table)?

like image 815
Hailwood Avatar asked Sep 29 '22 20:09

Hailwood


People also ask

How do I insert data from one table to another table?

The SQL INSERT INTO SELECT Statement The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.

How do I insert table values from one database to another database?

INSERT INTO SQL statement is used to insert data from one database table to another. The INSERT INTO can be used to transfer data from one database to other database or between two tables in the same database.


1 Answers

INSERT INTO action_2_members (campaign_id, mobile, vote, vote_date)  
SELECT campaign_id, from_number, received_msg, date_received
  FROM `received_txts`
 WHERE `campaign_id` = '8'
like image 440
zerkms Avatar answered Oct 17 '22 22:10

zerkms