처음 10개의 레코드를 선택하려면 먼저 레코드를 오름차순 또는 내림차순으로 정렬할 수 있습니다. 이를 통해 LIMIT 10을 사용하여 10개의 레코드만 가져옵니다. -
select *from (select *from yourTableName ORDER BY yourColumnName ASC LIMIT 10)anyAliasName ORDER BY yourColumnName DESC;
먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable683(Page int); Query OK, 0 rows affected (0.83 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable683 values(100); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(101); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(102); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(103); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(104); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable683 values(105); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable683 values(106); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(107); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable683 values(108); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable683 values(109); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable683 values(110); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable683 values(111); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable683 values(112); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable683 values(113); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable683 values(114); Query OK, 1 row affected (0.10 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable683;
이것은 다음과 같은 출력을 생성합니다 -
+------+ | Page | +------+ | 100 | | 101 | | 102 | | 103 | | 104 | | 105 | | 106 | | 107 | | 108 | | 109 | | 110 | | 111 | | 112 | | 113 | | 114 | +------+ 15 rows in set (0.00 sec)
다음은 MySQL에서 처음 10개의 레코드를 선택하는 쿼리입니다 -
mysql> select *from (select *from DemoTable683 ORDER BY Page ASC LIMIT 10)tbl ORDER BY Page DESC;
이것은 다음과 같은 출력을 생성합니다 -
+------+ | Page | +------+ | 109 | | 108 | | 107 | | 106 | | 105 | | 104 | | 103 | | 102 | | 101 | | 100 | +------+ 10 rows in set (0.00 sec)