SQL ORDER BY

1 개요[ | ]

ORDER BY
SQL ORDER BY
  • 조회결과를 정렬하는 SQL 키워드
  • 정렬방향은 ASC(오름차순) 또는 DESC(내림차순)인데 ASC는 생략할 수 있다.
즉, 생략되어 있다면 ASC(오름차순)라는 의미이며, 그래서 예시에서 ASC가 나오는 일은 별로 없다.
결론적으로 내림차순이 필요한 경우에만 DESC를 쓰면 된다.
SELECT 컬럼명1, 컬럼명2, ...
FROM 테이블명
ORDER BY 컬럼명1 정렬방향, 컬럼명2 정렬방향;


SELECT * FROM Customers
ORDER BY Country;

2 실행 예시[ | ]

SELECT custId, contactName, country FROM Northwind.Customer
-- country 오름차순, custId 내림차순
SELECT custId, contactName, country FROM Northwind.Customer ORDER BY country, custId DESC

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}