Home > Database > Mysql Tutorial > How to Efficiently Transfer Data Between SQL Tables Using INSERT INTO...SELECT?

How to Efficiently Transfer Data Between SQL Tables Using INSERT INTO...SELECT?

Patricia Arquette
Release: 2025-01-04 18:09:40
Original
881 people have browsed it

How to Efficiently Transfer Data Between SQL Tables Using INSERT INTO...SELECT?

Pulling Data from One Table to Insert into Another in SQL

The task at hand involves transferring data from a raw data table (received_txts) to a processed data table (action_2_members) in SQL. To achieve this, you can utilize the INSERT INTO... SELECT syntax:

INSERT INTO target_table (column1, column2, ...)
SELECT column1, column2, ...
FROM source_table
WHERE condition;
Copy after login

In your specific case, to insert data from the received_txts table into the action_2_members table, the SQL statement would be:

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'
Copy after login

This query seamlessly achieves the desired operation:

  • It retrieves the necessary data from the received_txts table using the SELECT statement.
  • Filtering the results by campaign_id = '8', it ensures the insertion of specific campaign data into the target table.
  • The INSERT INTO statement takes the retrieved data and inserts it into the action_2_members table, populating its columns accordingly.

By executing this query, you can efficiently transfer data between tables, enabling you to process and utilize it further in your database operations.

The above is the detailed content of How to Efficiently Transfer Data Between SQL Tables Using INSERT INTO...SELECT?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template