--- id: sql-order-by title: "SQL Order By" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL ORDER BY Keyword", "ORDER BY clause", "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", "orderby", "sorting"] raw_sources: ["https://www.w3schools.com/sql/sql_orderby.asp"] applied_in: [] github_commit: "" --- # [[SQL Order By]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) ORDER BY sorts a result-set by one or more columns, ascending by default, and can mix ascending/descending direction per column. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **ORDER BY keyword** β€” sorts the result-set in ascending (ASC, default) or descending (DESC) order. [S1] - **Syntax** β€” `SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;`. [S1] - **Alphabetical sorting** β€” for text columns, ORDER BY sorts alphabetically (and reverse-alphabetically with DESC). [S1] - **Multi-column sort** β€” sorting by several columns applies the first column as primary sort key and subsequent columns as tie-breakers. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Per-column direction** β€” each column in a multi-column ORDER BY can independently specify ASC or DESC, e.g. `ORDER BY Country ASC, CustomerName DESC`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Sort ascending by default: `SELECT * FROM Products ORDER BY Price;`. [S1] - Sort descending: `SELECT * FROM Products ORDER BY Price DESC;`. [S1] - Sort multiple columns, Country first then CustomerName as tie-break: `SELECT * FROM Customers ORDER BY Country, CustomerName;`. [S1] - Combine directions per column: `SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC;`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” 정렬은 이후 JOIN/GROUP BY κ²°κ³Όλ₯Ό μ‚¬λžŒμ΄ 읽기 μ’‹κ²Œ λ§Œλ“œλŠ” 데 반볡적으둜 ν•¨κ»˜ 쓰인닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Sort ascending (default) then descending (SQL): ```sql SELECT * FROM Products ORDER BY Price; SELECT * FROM Products ORDER BY Price DESC; ``` Multi-column sort with mixed direction (SQL): ```sql SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC; ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Select]], [[SQL Where]], [[SQL Group By]] - **μ°Έμ‘° λ§₯락:** 쑰회 κ²°κ³Όλ₯Ό μ •λ ¬ν•΄μ„œ λ³΄μ—¬μ€˜μ•Ό ν•˜λŠ” λͺ¨λ“  μΏΌλ¦¬μ—μ„œ μž¬μ‚¬μš©λ˜λŠ” κΈ°λ³Έ 문법. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL ORDER BY Keyword β€” https://www.w3schools.com/sql/sql_orderby.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL ORDER BY Keyword" page (Astra wiki-curation, P-Reinforce v3.1 format).