Home > Database > Mysql Tutorial > How Can I Universally Insert Data from One Table to Another Using SQL?

How Can I Universally Insert Data from One Table to Another Using SQL?

Mary-Kate Olsen
Release: 2025-01-24 04:03:14
Original
388 people have browsed it

How Can I Universally Insert Data from One Table to Another Using SQL?

A Single SQL Syntax for Data Insertion Between Tables

Moving data from one table to another is a frequent database operation. While most database systems support this, remembering the specific syntax for each can be difficult. Fortunately, a standard SQL approach works across many systems:

<code class="language-sql">INSERT INTO table1 (column1)
SELECT col1
FROM table2;</code>
Copy after login

This inserts data from selected columns in the source table (table2) into the corresponding columns of the target table (table1).

Confirmed Functionality:

This method has been successfully tested on these database systems:

  • Oracle
  • Microsoft SQL Server
  • MySQL
  • PostgreSQL
  • SQLite v3
  • Teradata
  • DB2
  • Sybase
  • Vertica
  • HSQLDB
  • H2
  • AWS RedShift
  • SAP HANA
  • Google Spanner

The above is the detailed content of How Can I Universally Insert Data from One Table to Another Using SQL?. 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