--- id: sql-union-all title: "SQL Union All" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL UNION ALL Operator", "UNION ALL operator"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "union", "union-all"] raw_sources: ["https://www.w3schools.com/sql/sql_union_all.asp"] applied_in: [] github_commit: "" --- # [[SQL Union All]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) UNION ALL combines result-sets like UNION but keeps every row including duplicates, under the same same-columns/types/order requirements. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **UNION ALL operator** β€” combines the result-set of two or more SELECT statements, including all rows and duplicates. [S1] - **Requirements** β€” identical to UNION: same number of columns, similar data types, same column order across all SELECT statements. [S1] - **Syntax** β€” `SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2;`. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **UNION vs. UNION ALL is a dedup toggle** β€” same syntax and requirements as UNION; the only behavioral difference is whether duplicate rows across the combined sets survive. [S1] ## βš–οΈ 비ꡐ 및 선택 κΈ°μ€€ (Comparison & decision criteria) | ν•­λͺ© (Option) | μž₯점 | 단점 | μ–Έμ œ 선택 | |---|---|---|---| | **UNION** | 쀑볡 μžλ™ 제거, κΉ”λ”ν•œ κ²°κ³Ό | 쀑볡 제거 μ—°μ‚°μœΌλ‘œ 인해 UNION ALL보닀 느릴 수 있음 | 고유 κ°’ λͺ©λ‘μ΄ ν•„μš”ν•  λ•Œ | | **UNION ALL** | 쀑볡 제거 연산이 μ—†μ–΄ 더 빠름, 원본 ν–‰ 수 보쑴 | 쀑볡 행이 κ·ΈλŒ€λ‘œ λ‚¨μŒ | μ„±λŠ₯이 μ€‘μš”ν•˜κ±°λ‚˜ 쀑볡 μžμ²΄κ°€ 의미 μžˆλŠ” 데이터(예: 개수 집계)일 λ•Œ | ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - All countries including duplicates: `SELECT Country FROM Customers UNION ALL SELECT Country FROM Suppliers ORDER BY Country;`. [S1] - Filtered UNION ALL: `SELECT City, Country FROM Customers WHERE Country='Germany' UNION ALL SELECT City, Country FROM Suppliers WHERE Country='Germany' ORDER BY City;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” 쀑볡 제거 λΉ„μš©μ„ ν”Όν•˜κ³  μ‹Άκ±°λ‚˜ 쀑볡 μžμ²΄κ°€ 의미 μžˆλŠ” 둜그/집계성 μΏΌλ¦¬μ—μ„œ UNION λŒ€μ‹  μ„ νƒλœλ‹€. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Combine result-sets keeping duplicates (SQL): ```sql SELECT Country FROM Customers UNION ALL SELECT Country FROM Suppliers ORDER BY Country; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Union]], [[SQL Select Distinct]] - **μ°Έμ‘° λ§₯락:** UNION의 쀑볡-보쑴 버전 β€” μ„±λŠ₯이 μ€‘μš”ν•˜κ±°λ‚˜ 쀑볡이 의미 μžˆλŠ” κ²½μš°μ— UNION λŒ€μ‹  선택. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL UNION ALL Operator β€” https://www.w3schools.com/sql/sql_union_all.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL UNION ALL Operator" page (Astra wiki-curation, P-Reinforce v3.1 format).