Education*
Devops
Architecture
F/B End
B.Chain
Basic
Others
CLOSE
Search For:
Search
BY TAGS
linux
HTTP
golang
flutter
java
fintech
개발환경
kubernetes
network
Docker
devops
database
tutorial
cli
분산시스템
www
블록체인
AWS
system admin
bigdata
보안
금융
msa
mysql
redis
Linux command
dns
javascript
CICD
VPC
FILESYSTEM
S3
NGINX
TCP/IP
ZOOKEEPER
NOSQL
IAC
CLOUD
TERRAFORM
logging
IT용어
Kafka
docker-compose
Dart
MySQL ORDER BY
Recommanded
Free
YOUTUBE Lecture:
<% selectedImage[1] %>
yundream
2023-08-14
2022-08-24
1449
# ORDER BY 모든 쿼리는 연습용 데이터베이스를 통해서 실행해 볼 수 있다. [MySQL & SQL 스터디 준비](https://www.joinc.co.kr/w/mysql_study_ready) 를 참고하여 실습환경을 구축하자. SELECT Statement를 사용해서 테이블에서 데이터를 조회하면, 결과 값들은 정렬되지 않고 리턴된다. **ORDER BY** 절을 이용하면 결과 집합의 행을 정렬하여 조회 할 수 있다. ### Syntax ```sql SELECT column1, column2, column3, ... FROM table_name ORDER BY column1 [ASC|DESC] column2 [ASC|DESC] ...; ``` ORDER BY 절 뒤에 하나 이상의 정렬할 column을 설정할 수 있으며, ASC 혹은 DESC를 정렬 방식으로 설정 할 수 있다. * ASC : 오름차순 정렬 * DESC : 내림차순 정렬 ASC, DESC는 생략할 수 있다. 생략할 경우 ASC가 기본 적용된다. ### Example Products 테이블에서 상품가격(UnitPrices)을 기준으로 오름차순 정렬을 했다. ```sql SELECT ProductID, ProductName, UnitPrice FROM products ORDER BY UnitPrice ASC; ``` | ProductID | ProductName | UnitPrice | | --------- | ----------- | --------- | | 33 | Geitost | 2.5000 | | 24 | Guaraná Fantástica | 4.5000 | | 13 | Konbu | 6.0000 | | 52 | Filo Mix | 7.0000 | 동일한 데이터를 내림차순으로 정렬해 보자. ```sql SELECT ProductID, ProductName, UnitPrice FROM products ORDER BY UnitPrice DESC; ``` | ProductID | ProductName | UnitPrice | | --------- | ----------- | --------- | | 38 | Côte de Blaye | 263.5000 | | 29 | Thüringer Rostbratwurst | 123.7900 | | 9 | Mishi Kobe Niku | 97.0000 | | 20 | Sir Rodney's Marmalade | 81.0000 | Products 데이터를 가격으로 먼저 정렬하고 그 다음 상품명으로 정렬했다. 결과 값은 중요 부분만 출력했다. ```sql SELECT ProductID, ProductName, UnitPrice FROM products ORDER BY UnitPrice DESC, ProductName ASC; ``` | ProductID | ProductName | UnitPrice | | --------- | ----------- | --------- | | 67 | Laughing Lumberjack Lager | 14.0000 | | 25 | NuNuCa Nuß-Nougat-Creme | 14.0000 | | 34 | Sasquatch Ale | 14.0000 | | 42 | Singaporean Hokkien Fried Mee | 14.0000 | | 58 | Escargots de Bourgogne | 13.2500 | ## 참고 [SQL Study With MySQL](https://www.joinc.co.kr/w/sql_study_with_mysql_index) 에서 MySQL과 관련된 다른 문서들을 읽을 수 있습니다.
Recent Posts
Vertex Gemini 기반 AI 에이전트 개발 06. LLM Native Application 개발
최신 경량 LLM Gemma 3 테스트
MLOps with Joinc - Kubeflow 설치
Vertex Gemini 기반 AI 에이전트 개발 05. 첫 번째 LLM 애플리케이션 개발
LLama-3.2-Vision 테스트
Vertex Gemini 기반 AI 에이전트 개발 04. 프롬프트 엔지니어링
Vertex Gemini 기반 AI 에이전트 개발 03. Vertex AI Gemini 둘러보기
Vertex Gemini 기반 AI 에이전트 개발 02. 생성 AI에 대해서
Vertex Gemini 기반 AI 에이전트 개발 01. 소개
Vertex Gemini 기반 AI 에이전트 개발-소개
Archive Posts
Tags
database
mysql
sql
SQL tutorial with MySQL
Copyrights © -
Joinc
, All Rights Reserved.
Inherited From -
Yundream
Rebranded By -
Joonphil
Recent Posts
Archive Posts
Tags