MySQL 기초

정렬 (order)


지정된 칼럼을 기준으로 행을 정렬


SELECT * FROM 테이블명 ORDER BY 정렬의 기준으로 사용할 열 [DESC | ASC]


CREATE TABLE `student` (
  `id` tinyint(4) NOT NULL,
  `name` char(4) NOT NULL,
  `sex` enum('남자','여자') NOT NULL,
  `address` varchar(50) NOT NULL,
  `distance` INT NOT NULL,
  `birthday` datetime NOT NULL,
  PRIMARY KEY (`id`)
INSERT INTO `student` VALUES (2, '박재숙', '남자', '서울',  10, '1985-10-26 00:00:00');
INSERT INTO `student` VALUES (1, '이숙경', '여자', '청주', 200, '1982-11-16 00:00:00');
INSERT INTO `student` VALUES (3, '백태호', '남자', '경주', 350, '1989-2-10 00:00:00');
INSERT INTO `student` VALUES (4, '김경훈', '남자', '제천', 190, '1979-11-4 00:00:00');
INSERT INTO `student` VALUES (8, '김정인', '남자', '대전', 200, '1990-10-1 00:00:00');
INSERT INTO `student` VALUES (6, '김경진', '여자', '제주', 400, '1985-1-1 00:00:00');
INSERT INTO `student` VALUES (7, '박경호', '남자', '영동', 310, '1981-2-3 00:00:00');
select * from student order by distance desc;
select * from student order by distance desc, address asc;


댓글 본문
  1. raphaelhubert
    Need to repair your smartphone, PC, MacBook, or other hardware? Icelltech is a one-stop solution for all your tech needs. We buy, sell, and repair your gadgets. You can save money and time by giving our team of technical experts with significant capabilities to repair your devices at a reasonable process in the market. Based in Chatham and Leamington Ontario, the company has established itself as a professional platform to give services according to the aspirations of the customers at very competitive rates with quality assurance.
    For more info visit
  2. ameliafernandez
    This is a much better contribution and it helps us. Thanks for sharing this post. I think students Need for their better results. I've got you book marked to check out new thingѕ you post.
  3. CharlotteT
    I’m really impressed about the info you provide in your articles. I must say am highly overwhelmed by your whole story. It’s not easy to get such quality information online nowadays. I look forward to staying here for a long time.
  4. romandavis
    This is the best source for those students who have to work for their earning and they can not attend the regular classes. Online courses are very beneficial for them to continue their study.
  5. samantha
    Thanks for the introduction, it looks very good, I am very fortunate to know this information.
  6. hannahberry
    This is a positive website, which has helped me understand some of the issues involved. I am pleased I have discovered it, although I will check back any additional posts you post soon.
  7. johnnydavid
    Thank you for sharing this! Just what I’ve been searching for. I am a Senior Web Developer. Providing all types of digital services.
  8. victormartin
    Thank you for providing eye-opening article for codding. Advacned SEO services contact advanced SEO Company. here:
  9. 오더바이가 오토바이로 들려요.
  10. carolinewebb
    Beneficial information, coding and video for those people who are in IT field, web developer, and beginners of IT learners. Thanks a lot for sharing it.

    Marketing personal statement writer,
  11. AlyssaPatterson
    Very knowledgeable video which specify Sort rows by specified column you shared with us with details of order, grammar and example. Thank you. Keep sharing.

  12. 곰o빠
  13. sheis
    잘 봤어요^^
  14. NamJin Kim
  15. JustStudy
  16. 인문대에이스
    가장 앞에 있는 ID를 시퀀스를 사용해서 가입한 순서대로 알아서 번호가 저장되도록 하고 싶은데 어떻게 해야 할까요???
  17. 이주환
    2016. 04. 12.
    정렬을 통해 게시판 최신순으로 정렬이 요긴하게 사용되겠군요.
    더더욱 많은 활용법이 있겠지만요 ㅎ_ㅎ.
  18. SK Kim
    phpMyAdmin 최신 버전에서는 복수 정렬 지원 됩니다.
  19. Wonil Shim
    '조회' 챕터에 Select문 형식을 보면, 아래와 같이 정리 해 주신 것이 있네요.
    SELECT 칼럼명1, 칼럼명2
    [FROM 테이블명 ]
    [GROUP BY 칼럼명]
    [ORDER BY 칼럼명 [ASC | DESC]]
    [LIMIT offset, 조회 할 행의 수]
    • 박고잉
      오도바이랑 그룹바이랑 같이 쓰려면 어떤걸 먼저 써야 하나요.
    • 짱구
      대전 , 청주 내림차순 기준이 알파벳인가요? 한글 내림차순 기준을 모르겠어요
    • WayneKing
      보고보고 또 보고 장보고

      아~ 내 멘탈
    • 조신부리
    • 이은영
      예제에 name char(6)으로 해야 한국어 3글자가 들어갑니다. 지금 예제는 잘려서 들어가네요 ㅠ
    • 샤핀
      감사합니다. ^^
    버전 관리
    현재 버전
    선택 버전
    graphittie 자세히 보기