DB/명령프롬프트 - mysql

[MySQL] 원하는 위치의 데이터 추출 limit

congs 2023. 3. 27. 09:01

원하는 위치의 데이터 추출

: limit 시작번지, 개수;

  • 시작번지부터 개수만큼 추출
  • 보통 서식의 맨뒤에 위치!
< 0번지부터 3개 추출 >
mysql> select * from student limit 0,3;
+------+--------+------+---------+----------+-------+
| num  | name   | age  | address | major    | score |
+------+--------+------+---------+----------+-------+
| 1111 | 홍길동 |   23 | seoul   | computer |    89 |
| 2222 | 강길순 |   24 | seoul   | English  |    87 |
| 3333 | 이순신 |   22 | Inchen  | English  |    57 |
+------+--------+------+---------+----------+-------+
3 rows in set (0.00 sec)

< 1~3등을 limit이용하여 출력 >
mysql> select * from student order by score desc limit 0,3;
+------+--------+------+---------+----------+-------+
| num  | name   | age  | address | major    | score |
+------+--------+------+---------+----------+-------+
| 6666 | 다래냥 |    1 | Inchen  | computer |   100 |
| 8888 | 다래잉 |   26 | Inchen  | computer |    99 |
| 5555 | 유관순 |   21 | suwon   | Computer |    97 |
+------+--------+------+---------+----------+-------+
3 rows in set (0.00 sec)