먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(30) ); Query OK, 0 rows affected (0.74 sec)
삽입 명령을 사용하여 테이블에 레코드 삽입 -
mysql> insert into DemoTable(ClientName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName) values('Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ClientName) values('Robert'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(ClientName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ClientName) values('Bob'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(ClientName) values('Carol'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(ClientName) values('Sam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(ClientName) values('Mike'); Query OK, 1 row affected (0.12 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select * from DemoTable;
이것은 다음과 같은 출력을 생성합니다 -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | | 5 | Bob | | 6 | Carol | | 7 | Sam | | 8 | Mike | +----------+------------+ 8 rows in set (0.00 sec)
다음은 시작 값에서 MySQL Order의 쿼리입니다 -
mysql> select *from DemoTable order by ClientId < 5,ClientId;
이것은 다음과 같은 출력을 생성합니다 -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 5 | Bob | | 6 | Carol | | 7 | Sam | | 8 | Mike | | 1 | John | | 2 | Chris | | 3 | Robert | | 4 | David | +----------+------------+ 8 rows in set (0.00 sec)