--- id: sql-select-distinct title: "SQL Select Distinct" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL SELECT DISTINCT Statement", "DISTINCT keyword", "SQL 쀑볡 제거"] 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", "distinct", "select"] raw_sources: ["https://www.w3schools.com/sql/sql_distinct.asp"] applied_in: [] github_commit: "" --- # [[SQL Select Distinct]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) SELECT DISTINCT returns only unique values from a column, collapsing duplicate rows that a plain SELECT would otherwise repeat. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **SELECT DISTINCT** β€” returns only distinct (unique) values, removing duplicate rows from the result. [S1] - **Syntax** β€” `SELECT DISTINCT column1, column2, ... FROM table_name;`. [S1] - **COUNT(DISTINCT column)** β€” counts the number of unique values in a column, but is not supported in Microsoft Access. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Dedup-then-count workaround** β€” for databases lacking `COUNT(DISTINCT ...)` (e.g. MS Access), wrap a `SELECT DISTINCT` subquery and `COUNT(*)` the outer result: `SELECT Count(*) AS DistinctCountries FROM (SELECT DISTINCT Country FROM Customers);`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Without DISTINCT, a query returns the column's value from every record, including repeats: `SELECT Country FROM Customers;`. [S1] - With DISTINCT, only unique values are returned: `SELECT DISTINCT Country FROM Customers;`. [S1] - Counting unique values directly: `SELECT COUNT(DISTINCT Country) FROM Customers;` β€” not supported on MS Access, which needs the subquery workaround above. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **DBMS 차이**: `COUNT(DISTINCT column_name)`이 MS Accessμ—μ„œλŠ” μ§€μ›λ˜μ§€ μ•ŠλŠ”λ‹€λŠ” 점이 λͺ…μ‹œμ μœΌλ‘œ 언급됨 β€” 방언별 차이가 쑴재. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” 이후 COUNT() μ±•ν„°μ—μ„œ DISTINCTμ™€μ˜ 쑰합이 더 닀뀄진닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Select unique values (SQL): ```sql SELECT DISTINCT Country FROM Customers; ``` Count unique values, MS Access-safe (SQL): ```sql SELECT Count(*) AS DistinctCountries FROM (SELECT DISTINCT Country FROM Customers); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Select]], [[SQL Count]], [[SQL Group By]] - **μ°Έμ‘° λ§₯락:** SELECT 결과의 쀑볡을 μ œκ±°ν•΄μ•Ό ν•  λ•Œ μ°Έμ‘°ν•˜λŠ” λ¬Έμ„œ β€” COUNT()와 κ²°ν•©ν•΄ κ³ μœ κ°’ 개수λ₯Ό μ…€ λ•Œ 자주 ν•¨κ»˜ 쓰인닀. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL SELECT DISTINCT Statement β€” https://www.w3schools.com/sql/sql_distinct.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL SELECT DISTINCT Statement" page (Astra wiki-curation, P-Reinforce v3.1 format).