--- id: sql-insert-into-select title: "SQL Insert Into Select" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL INSERT INTO SELECT Statement", "INSERT INTO SELECT"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "insertintoselect"] raw_sources: ["https://www.w3schools.com/sql/sql_insert_into_select.asp"] applied_in: [] github_commit: "" --- # [[SQL Insert Into Select]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) INSERT INTO SELECT copies rows from one existing table into another EXISTING table, leaving the target's current rows untouched β€” unlike SELECT INTO, which creates a brand-new table. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **INSERT INTO SELECT statement** β€” copies data from an existing table and inserts it into another existing table. [S1] - **Data type matching required** β€” source and target table column data types must match. [S1] - **Target rows preserved** β€” existing records in the target table are unaffected by the insert. [S1] - **Syntax (all columns)** β€” `INSERT INTO target_table SELECT * FROM source_table WHERE condition;` β€” requires column count/order to match exactly if names are omitted. [S1] - **Syntax (specific columns)** β€” `INSERT INTO target_table (column1, column2, ...) SELECT column1, column2, ... FROM source_table WHERE condition;`. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Partial-column copy leaves NULLs** β€” copying only some target columns (e.g. `CustomerName, City, Country`) leaves the unmapped target columns as NULL for the inserted rows. [S1] - **Filtered source-to-target copy** β€” a WHERE clause on the source SELECT restricts which rows get copied (e.g. only German suppliers). [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Copy specific columns from Suppliers into Customers: `INSERT INTO Customers (CustomerName, City, Country) SELECT SupplierName, City, Country FROM Suppliers;`. [S1] - Copy all columns (requires matching schema): `INSERT INTO Customers SELECT * FROM Suppliers;`. [S1] - Copy a filtered subset: `INSERT INTO Customers (CustomerName, City, Country) SELECT SupplierName, City, Country FROM Suppliers WHERE Country='Germany';`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” SELECT INTO(μƒˆ ν…Œμ΄λΈ” 생성)와 λŒ€λΉ„λ˜λŠ”, κΈ°μ‘΄ ν…Œμ΄λΈ” κ°„ 데이터 이관에 μ“°μ΄λŠ” λ¬Έμ„œλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Copy filtered rows between existing tables (SQL): ```sql INSERT INTO Customers (CustomerName, City, Country) SELECT SupplierName, City, Country FROM Suppliers WHERE Country='Germany'; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Select Into]], [[SQL Insert Into]], [[SQL Where]] - **μ°Έμ‘° λ§₯락:** κΈ°μ‘΄ ν…Œμ΄λΈ” κ°„ 데이터 이관 μ‹œ μ‚¬μš© β€” μƒˆ ν…Œμ΄λΈ”μ„ λ§Œλ“€μ–΄μ•Ό ν•œλ‹€λ©΄ λŒ€μ‹  SELECT INTOλ₯Ό μ‚¬μš©. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL INSERT INTO SELECT Statement β€” https://www.w3schools.com/sql/sql_insert_into_select.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL INSERT INTO SELECT Statement" page (Astra wiki-curation, P-Reinforce v3.1 format).